admin管理员组文章数量:1355879
I need to add a class to div that is wrapped around the select element upon validation.
$("#Form").validate({
invalidHandler: function (form, validator) {
$("[id$='_DropDownList']").each(function () {
// How do I figure out if $(this) is valid or invalid?
// Add the class below if invalid.
$(this).parent().addClass("error");
});
}
});
I need to add a class to div that is wrapped around the select element upon validation.
$("#Form").validate({
invalidHandler: function (form, validator) {
$("[id$='_DropDownList']").each(function () {
// How do I figure out if $(this) is valid or invalid?
// Add the class below if invalid.
$(this).parent().addClass("error");
});
}
});
Share
Improve this question
edited Jan 6, 2011 at 16:36
Nick Craver
631k138 gold badges1.3k silver badges1.2k bronze badges
asked Jan 6, 2011 at 16:08
mhenrymhenry
1,4875 gold badges18 silver badges31 bronze badges
3 Answers
Reset to default 6You can use the .valid()
method, like this:
$("#Form").validate({
invalidHandler: function (form, validator) {
$("[id$='_DropDownList']").each(function () {
if(!$(this).valid())
$(this).parent().addClass("error");
});
}
});
However, the highlight
and unhightlight
options are specifically for this:
$("#Form").validate({
highlight: function(element, errorClass, validClass) {
$(element).parent().removeClass(validClass).addClass(errorClass);
},
unhighlight: function(element, errorClass, validClass) {
$(element).parent().removeClass(errorClass).addClass(validClass);
}
});
It looks like this code is correct:
$(this).parent().addClass("error");
Maybe your issue is with the code surrounding it... Try moving your addClass line outside the function it is in to see if it work there.
invalidHandler
is only called when the form is submitted and not valid. I believe adding your code under that function alone is enough.
本文标签: javascriptUsing jQuery Validate39s invalidHandler eventStack Overflow
版权声明:本文标题:javascript - Using jQuery Validate's invalidHandler event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743984552a2571220.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论