我的jquery验证注册表单中的一些问题 [英] some issues in my jquery validation registration form
本文介绍了我的jquery验证注册表单中的一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是当我按下按钮或输入我的last
和first
名称时,其中一个没有对它的jquery验证.以及如何使三个组合框具有1条规则的jquery验证而不是三个弹出框?
My problem is when i press the button or type in my last
and first
name one of them dont have a jquery validation on it. And how do i make the three comboboxes have a 1 rule jquery validation instead of three poping out?
当前输出: http://jsfiddle.net/5kcsn/12/
$('form').validate({
rules: {
fname: {
minlength: 3,
maxlength: 15,
required: true
},
lname: {
minlength: 3,
maxlength: 15,
required: true
},
month: {
required: true
},
day: {
required: true
},
year: {
required: true
}
},
highlight: function (element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function (element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function (error, element) {
if (element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
推荐答案
选中此 工作小提琴 a>
Check this Working Fiddle
-
您需要对元素进行分组.
You need to group the elements.
groups: {
DateofBirth: "month day year"
},
然后在errorPlacement:
部分中添加
errorPlacement: function (error, element) {
if (element.attr("name") == "day" || element.attr("name") == "month" || element.attr("name") == "year")
error.insertAfter(".dateWrap");
else
error.insertAfter(element);
if (element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
- 对于
lname
问题,您在html中输入的名字字段为id="lname"
.因此,有两个<input>
元素,其ID为lname
. - For
lname
issue, your input field in html for first name hasid="lname"
. So there were two<input>
elements with the ID aslname
.
参考: .validate()组 .
Reference : .validate() groups.
这篇关于我的jquery验证注册表单中的一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文