如何使用 jQuery 验证插件获取对提交按钮的引用?
function defSubmHendler(){
$myform.validate({
rules: rules,
messages: messages,
submitHandler: function() {
event.preventDefault();
if (~this form id == A){
condition1;
}
else if (~this form id == B){
condition2;
} else {}
...
$.ajax({
...
});
}
});
}
在本例中this == $.validator。我需要对submitHandler 中的提交按钮/表单的引用。
最佳答案
考虑为您的提交按钮提供一个 id
并像这样引用它:
submitHandler: function() {
//Your submit button referenced by its ID
$("#mySubmitButton").doStuff();
}
或者,使用 SubmitHandler 函数中的 form
元素并查找该表单中包含的提交按钮:
submitHandler: function(form) {
//Via the form argument passed to the submitHandler
var btnSubmit = form.find(":submit");
}
关于javascript - 如何使用 jQuery 验证插件获取提交按钮的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23595897/