【问题标题】:jQuery Validate Uncaught TypeError: Cannot call method 'getAttribute' of undefinedjQuery Validate Uncaught TypeError:无法调用未定义的方法“getAttribute”
【发布时间】:2012-09-06 02:42:29
【问题描述】:

给定这个 HTML 使用 jQuery 验证

 <input id="accept-terms" type="checkbox" class="required"/> 
 <label for="accept-terms"> I accept the <asp:HyperLink ID="termsLink" runat="server" Target="_blank">terms and condtions</asp:HyperLink> of sale.</label>
 <label for="accept-terms" class="error-text">You must accept the terms and conditions before purchasing</label>

我收到此错误:

未捕获的类型错误:无法调用未定义的方法“getAttribute”

【问题讨论】:

    标签: jquery html forms jquery-validate


    【解决方案1】:

    “名称”属性缺失:

    <input id="accept-terms" name="accept-terms" type="checkbox" class="required"/> 
    

    (我花了一段时间才弄清楚,所以我想我会分享问题和解决方案)

    另外:检查下面的 cmets,因为其他人已经发布了相同异常的其他原因。

    【讨论】:

    • 如果您在另一个表单中有一个表单,显然也会发生这种情况。
    • 我在 TextArea 中遇到了同样的问题,它已经有一个属性 'name'
    • 刚刚读到这也可能是因为缺少规则名称。在我的情况下,我创建了一个自定义规则,该规则没有正确加载,并且验证器无法找到它(因此它抛出了“Uncaught TypeError: Cannot call method 'getAttribute' of undefined”)跨度>
    • 只是为了后代我也遇到了这个问题。对我来说,事实证明我将“minlength”错误地输入为“minlengh”。真希望我能回到那 4 个小时。只是想把它放在这里检查所有拼写,以防有人发现自己处于类似情况。
    • 对我来说,忘记从附加到a 标签的点击监听器内部调用e.preventDefault();。代码正在运行,但正在记录错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多