jQuery使用回调验证添加和删除类 [英] jQuery Validate add and remove classes using callbacks
本文介绍了jQuery使用回调验证添加和删除类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jQuery Validate插件,并且试图使用errorPlacement
和success
回调来添加和删除引导类has-error
.
I am working with the jQuery Validate plugin and I am trying to use the errorPlacement
and success
callbacks to add and remove the bootstrap class has-error
.
当前,errorPlacement
回调有效,但由于success
回调返回错误标签(我没有使用),所以我不确定该怎么做.我需要再次访问success
中的输入,但是我不知道该怎么做.
Currently, the errorPlacement
callback works but since the success
callback returns the error label (which I'm not using) I'm not sure what to do. I need access to my input again in success
but I don't know how to do it.
$('#msform').validate({
submitHandler: function (form) {
alert('valid form submitted');
return false; // for demo
},
errorPlacement: function(error, element) {
$(element).parent().addClass('has-error');
$(element).css('border-color', '#a94442');
},
success: function(label) {
label.removeClass('has-error').text('ok');
},
invalidHandler: function(event, validator) {
var errors = validator.numberOfInvalids();
}
});
有人可以帮忙吗?谢谢.
Can anybody help? Thanks.
查看全文