jQuery .submit()验证问题 [英] jquery .submit() validate problem
问题描述
因此,我编写的此验证内容有效,但由于某种原因,我需要单击两次以提交表单.有什么想法吗?
So this validation thing I wrote works but for some reason I need to click twice for the form to submit. Any ideas?
$('#signup').submit(function() {
console.log('Clicked');
$('#signup').validate({
rules: {
FNAME: {
required: true,
notPlaceholder: true
},
email: {
required: true,
notPlaceholder: true,
email: true
}
},
errorLabelContainer: "div.error",
submitHandler: function(form) {
$.colorbox({width:"300px", href:'thankyou.html'});
$('#signup').fadeOut();
}
});
return false;
});
谢谢
推荐答案
您的$('#signup').validate
调用位于内部 $('#signup').submit
,这意味着直到用户首次尝试验证器才被附加提交表格.正如Cybernate在评论中指出的那样,将validate
调用移到submit
调用之前将首先附加验证器.
Your $('#signup').validate
call is inside $('#signup').submit
, which means the validator isn't attached until the first time the user tries to submit the form. As Cybernate pointed out in a comment, moving the validate
call before the submit
call will attach the validator first.
有点混乱; validate
实际上是设置验证,而不是立即执行.
It's a little confusing; validate
actually sets up validation, rather than performs it right away.
使用validate
设置验证后,您实际上可以将submit
调用更改为如下形式:
Once validation has been set up using validate
, you can actually change your submit
call to look like this:
$('#signup').submit(function() {
return $('#signup').valid();
});
这篇关于jQuery .submit()验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!