增强jquery.validation(验证组) [英] enhance the jquery.validation (validation group)
问题描述
大家好,我正在使用ASP.net,所以我使用下面的代码来做验证组。
http://fiddle.jshell.net/N5BYk/2/ [ ^ ]
现在我需要通过突出显示整个文本框和标签来增强验证,如果有错误,请参阅图像样本。
http://oi58.tinypic.com/iv8v3b.jpg [ ^ ]
$ b $下面的b是我怎么做的代码(不包括在小提琴里面)。
Hi all, im using ASP.net, so im using code as below to do the validation group.
http://fiddle.jshell.net/N5BYk/2/[^]
now i need to enhance the validation by highlight the whole textbox and label if there is an error, see the image for sample.
http://oi58.tinypic.com/iv8v3b.jpg[^]
below is the code how i do that (not included inside the fiddle).
$("#form1").validate({
highlight: function (element) {
$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
},
unhighlight: function (element) {
$(element).closest('.form-group').removeClass('has-error').addClass('has-success');
},
errorElement: 'span',
errorClass: 'help-block',
onsubmit: false,
errorPlacement: function (error, element) {
if (element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
i尝试了几种方法,但仍然没有成功,任何人都可以建议我吗?
i tried several ways, but still not success, anyone can advice me?
推荐答案
( #form1)。validate({
highlight: function (element){
("#form1").validate({ highlight: function (element) {
(element).closest(' .form-group')。removeClass(' has-success')。addClass(' has-error');
},
unhighlight: function (element){
(element).closest('.form-group').removeClass('has-success').addClass('has-error'); }, unhighlight: function (element) {
(element).closest( .form-group')。removeClass(' < span class =code-string> has-error')。addClass(' has-success');
},
errorElement:' span',
errorClass: ' help-block',
onsubmit: false ,
errorPlacement: function (错误,元素){
if (element.parent(' .input-group')。length){
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
(element).closest('.form-group').removeClass('has-error').addClass('has-success'); }, errorElement: 'span', errorClass: 'help-block', onsubmit: false, errorPlacement: function (error, element) { if (element.parent('.input-group').length) { error.insertAfter(element.parent()); } else { error.insertAfter(element); } } });
i尝试了几种方式,但仍然没有成功,任何人都可以建议我吗?
i tried several ways, but still not success, anyone can advice me?
这篇关于增强jquery.validation(验证组)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!