2012-09-13 41 views
10

考慮使用jQuery這個HTML驗證jQuery驗證遺漏的類型錯誤:無法調用 '的getAttribute' 未定義

<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> 

我得到這個錯誤:

Uncaught TypeError: Cannot call method 'getAttribute' of undefined

回答

22

'名稱' 屬性缺失:

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

(這花了我一段時間才弄清楚,所以我想我會分享這個問題和解決方案)

另請參閱下面的註釋,因爲其他人發佈了相同例外的其他原因。

+3

如果您在另一個表單中有表單,這顯然也會發生。 –

+0

我與TextArea有同樣的問題,它已經有一個屬性「名稱」 – mbmihura

+0

只是讀取它也可能是因爲缺少規則名稱。在我的情景中,我創建了一個自定義規則,沒有正確加載,並且驗證程序無法找到它(所以它拋出了「Uncaught TypeError:無法調用未定義的方法'getAttribute') – mbmihura

相關問題