jQuery验证未捕获的TypeError:无法调用未定义的方法'getAttribute'

Mys*_*ter 10 html forms jquery jquery-validate

鉴于此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>
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

未捕获的TypeError:无法调用未定义的方法'getAttribute'

Mys*_*ter 23

缺少"name"属性:

<input id="accept-terms" name="accept-terms" type="checkbox" class="required"/> 
Run Code Online (Sandbox Code Playgroud)

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

另外:检查下面的评论,因为其他人已针对同一例外发布了其他原因.

  • 如果你在另一个表单中有一个表单,这显然也会发生. (3认同)