什麼是最好的JQuery的方式,以確保與「必需的」屬性所有輸入字段都完成JQuery的表單驗證
2
A
回答
3
使用.filter()
方法來檢查它們各自的價值,然後檢查結果的長度屬性:
var incomplete = $("input[required]").filter(function() {
return this.value === "";
});
if (incomplete.length) {
alert("Please fill in all the required fields");
}
請注意,名爲required
的屬性會使您的HTML無效。然而,data-required
可能是有效的HTML5,或者你可以給它們全部一個類並使用它作爲選擇器(這也會更有效)。
您也可以使用其中一個驗證插件:http://google.com/search?q=jquery+validation。
0
你可以嘗試使用jQuery驗證插件:
0
試試這個:
http://speckyboy.com/2009/12/17/10-useful-jquery-form-validation-techniques-and-tutorials-2/
0
例如:webreference
1
最好的jQuery驗證插件: http://bassistance.de/jquery-plugins/jquery-plugin-validation/
(至少我使用的一個,感覺最舒服的)
0
還有一個叫「valididty」插件,值得一提的是簡單的使用IMO認證插件。
0
您也可以嘗試表單驗證
0
bValidator插件(http://code.google.com/p/bvalidator/)只需在input
標籤的末尾添加兩個屬性:
required="required" js-name="name_to_be_displayed"
<script language="javascript" src="jquery.min.js"></script>
<script language="javascript" type="application/javascript">
$(function(){
$("#submit").click(function(){
$('input').each(function(index, value) {
var attb = $(this).attr('required');
var value = $(this).val();
if (attb == "required" && value == "") {
alert($(this).attr('js-name') + " " + 'value required');
$(this).focus();
return false;
}
});
});
});
</script>
<form action="index.php" method="post" enctype="multipart/form-data" target="_self">
<label> Name:
<input name="Name:" type="text" size="60" maxlength="60" required="required" js-name="Name" />
</label>
<br />
<label>Email:
<input name="Email:" type="email" value="" size="60" required="required" js-name="Email" />
</label>
<br />
<label>Phone:
<input name="Phone" type="text" size="60" required="required" js-name="Phone" />
</label>
<br />
<label>Country:
<input name="Country" type="text" size="60" required="required" js-name="Country" />
</label>
<br />
<input name="Submit" type="submit" id="submit" value="Submit" />
</form>
0
檢查這個簡單jQuery插件
0
valijate插件可能會幫助你。它使用'data-xxxx'屬性進行驗證。這裏是form validation guide。
相關問題
- 1. jQuery - 表單驗證
- 2. jquery表單驗證
- 3. jquery表單驗證
- 4. jquery表單驗證
- 5. jquery表單驗證
- 6. Jquery表單驗證
- 7. jQuery表單驗證
- 8. jquery:表單驗證
- 9. JQuery表單驗證
- 10. jquery表單驗證
- 11. Jquery對錶單子驗證的驗證
- 12. jQuery的表單驗證
- 13. jQuery的表單驗證
- 14. jQuery的表單驗證在
- 15. POST jQuery的表單驗證
- 16. jQuery的---驗證表單
- 17. jQuery表單驗證驗證年齡
- 18. Live Jquery表單驗證和CakePHP驗證
- 19. jQuery表單驗證無效
- 20. jQuery驗證表單問題
- 21. php,jquery,sql。表單驗證
- 22. Rails jquery ajax表單驗證
- 23. jQuery表單驗證問題
- 24. tinyMCE jQuery表單驗證
- 25. JQuery表單驗證序列
- 26. jquery表單驗證問題
- 27. jQuery Mobile表單驗證
- 28. JQuery表單驗證問題
- 29. 表單域; jquery驗證
- 30. 表單驗證Jquery對象
嗨安迪感謝這一點,你是對的HTML,但這是爲HTML5 :) – 2010-12-23 12:34:43