JQuery Validation插件submitHandler对我不起作用 [英] JQuery Validation Plugin submitHandler doesnt work for me
问题描述
您好我得到以下问题我的以下代码对我不起作用,我无法弄清楚原因。我希望你们能帮助我。
Hello i got the following issue my following code doesn't work for me and i cant figure out why. I hope you guys can help me.
编辑:提交处理程序根本不会被调用。我甚至没有得到警报信息。我想禁用提交按钮,直到表单被验证。
The submit handler simply doesn't get called. I don't even get the alert message. I wanted to disable the submit button till the form is validated.
$('form').validate({
onsubmit: true,
debug: true,
errorLabelContainer: "#errorBox",
rules: {
user_email: {
minlength: 4,
email: true,
required: true
},
user_textField: {
minlength: 3,
required: true
},
user_phone: {
required: true,
number: true,
minlength: 4
},
user_fax: {
number: true,
minlength: 4
},
user_plz: {
required: true,
number: true,
minlength: 5
}
},
submitHandler: function (form) {
$('form').find(":submit").attr("disabled", true).attr("value","Submitting...");
alert("hie");
form.submit();
}
});
我还有一个提交按钮:
<button class="btn btn-primary pull-right continuePaymentProcess" type="submit">Weiter</button>
最好的问候Grandy
Best Regards Grandy
推荐答案
您不需要 onsubmit:true
行,因为这是默认行为。 重要:根据文档,
You don't need the onsubmit: true
line because that's the default behavior. Important: as per docs,
在提交时验证表单。设置为false以仅使用其他事件进行验证。设置为函数以自行决定何时运行验证。 布尔值true不是有效值。
换句话说,您必须删除该行,因为 true
会破坏插件。
In other words, you must remove that line because true
will break the plugin.
至于 submitHandler
不工作,它按照文档工作。表格有效时, submitHandler
回调函数会触发 。
As far as the submitHandler
"not working", it works as per the documentation. The submitHandler
callback function fires when the form is valid.
你说,我想禁用提交按钮,直到表单被验证。
由于 submitHandler
在表单有效
之前不会被触发,在 表单验证之后,禁用该按钮的代码才会触发。
Since the submitHandler
doesn't get fired until the the form is valid
, your code to disable the button doesn't fire until after the form is validated.
查看您的代码: http://jsfiddle.net/ aDAGL /
这篇关于JQuery Validation插件submitHandler对我不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!