我已經寫seprate規則jQuery的validate()
命名爲login_auth
,我想這條規則是不呼籲每個按鍵但我想其他所有規則被稱爲onkeyup
。這意味着所有其他內置規則類似email
和password
應在每個密鑰上調用,但只應調用login_auth
onfocusout
或blur
。如何使jQuery Validate()規則爲onkeyup爲false?
1
A
回答
3
這是我最好的答案,直到你發佈你的實際的HTML和jQuery。
我知道沒有辦法選擇性地應用任何插件選項....而是它們會應用到插件的每個實例。
因此,我建議兩種形式,以便您可以擁有.validate()
的兩個唯一實例,並在一個表單上應用onkeyup: false
選項,同時允許onkeyup
在其他表單上正常工作。
HTML:
<form id="authForm" action="#">
login: <input type="text" name="login" /><br />
</form>
<form id="Form" action="yourAction" method="yourMethod">
email: <input type="text" name="email" /><br />
password: <input type="password" name="password" /><br />
<input type="submit" />
</form>
的jQuery:
$(document).ready(function() {
$('#authForm').validate({
onkeyup: false,
rules: {
login: {
login_auth: true, // your custom rule
required: true
}
}
});
$('#Form').validate({
rules: {
email: {
required: true,
email: true
},
password: {
required: true
}
},
submitHandler: function(form) {
if ($('#authForm').valid()) {
form.submit();
}
},
errorPlacement: function(error, element) {
$('#authForm').valid(); // force validation on first form when this form has error
error.insertAfter(element); // default error placement
}
});
});
3
$.validator.setDefaults({
onkeyup: function(element) {
if (element.name == '#emailid') {
return false;
}
}
});
在一個表單中,如果您想停止某個特定ID的關鍵事件,請嘗試此操作。
相關問題
- 1. 使用:的onkeyup =>爲使用jQuery
- 2. 如何使用Asciidoc作爲規則
- 3. 爲組規則
- 4. jQuery .validate規則似乎沒有應用? (的jsfiddle)
- 5. jquery-validate - addMethod - 如何應用引用兩個文本框的自定義規則?
- 6. 如何從jQuery Validate中的所有表單輸入中刪除'required'規則?
- 7. 如何使用如果規則在jquery
- 8. 如何使BluetoothDeviceInfo.Connected爲false?
- 9. 如何將nginx規則改寫爲htacces規則?
- 10. 如何將此Apache Rewrite規則轉換爲Tuckey UrlRewriteFilter規則?
- 11. 如何將規則集文件轉換爲FXCop規則dll?
- 12. 如何將mod_rewrite規則轉換爲nginx規則
- 13. 如何使用jQuery禁用CSS規則?
- 14. htaccess規則(mod_rewrite)轉換爲web.config規則
- 15. 如何在jQuery中使用OnKeyup
- 16. IIS規則轉換爲.htaccess規則
- 17. 爲jQuery驗證插件添加規則
- 18. jQuery對話框不規則行爲
- 19. OpenCV如果圖像爲「==」則如何獲得bool true,如果不是則爲false?
- 20. 將htaccess規則轉換爲nginx規則
- 21. 如何爲proguard編寫規則?
- 22. 如何爲cronjob應用.htaccess規則?
- 23. 如何爲此制定規則?
- 24. 如何爲PayPal IPN(htaccess)重寫規則?
- 25. false的計數爲1,如果是空數組,則爲false。爲什麼?
- 26. 標識規範設置爲false
- 27. 如何爲jQuery驗證規則創建FOR循環?
- 28. 計算兩個元素onkeyup - 如何將其轉換爲jQuery?
- 29. jquery validate
- 30. 爲什麼規則2的規則1後果影響行爲?
請有人幫忙 – Akki
如果您需要幫助,請顯示您的表單代碼... HTML和jQuery。 – Sparky
這裏回答類似的問題http://stackoverflow.com/a/17096209/678338 –