jQuery多种表单验证 [英] jQuery multiple form validation
问题描述
我在不同的页面中有多种形式,有没有办法写一个single function
来处理validation
或应该为每种形式的代码separately
编写代码.
I have multiple forms in different page, Is there a way to write a single function
which would take care of validation
or should i write code for each form separately
.
$(document).ready(function () {
$('#fvujq-form1').validate();
$('#fvujq-form2').validate();
});
注意:每种表单都有自己的规则.
Note: Each form has its own rules.
更新:
$("form").each(function () {
$(this).validate({
rules: {
username: {
required: true
},
password: {
required: true
},
name: {
required: true,
},
cperson: {
required: true,
}
},
submitHandler: function (form) {
return false; //temporarily prevent full submit
}
});
});
现在,不同页面中的username
和password
格式不同,并且name
和person
的格式也不同.以这种方式提交普通表单是否正确?
Now the username
and password
of different form and name
and person
is of different form in different page. Is it right to proceed in this way of having a common form submission.
推荐答案
如果需要的话,可以使用$("form")选择器来验证type类型的所有元素.不过,我不建议您专门针对具有多种形式的页面.
You can use the $("form") selector to validate all elements of type form if that's what you are asking for. I would not recommend that specifically for a page with multiple forms though.
这篇关于jQuery多种表单验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!