我想调用jquery函数来手动从单个字段中删除错误并重置错误标记。是否有一个与resetForm函数类似的函数?
答案 0 :(得分:11)
您可以执行以下操作来验证单个字段:
$('#your_field').valid();
也许它会帮助某人: - )
谢谢!
答案 1 :(得分:5)
无法找到内置于验证库的任何内容,但此黑客可以运行:
$('#email').removeClass('error').next('label.error').remove();
答案 2 :(得分:4)
this重置整个表单
var validator = $("#myform").validate();
validator.resetForm();
this将仅重置name
元素
$("#skip").click(function() {
var rules = $("#name").removeAttrs("min max"); // remove min and max
$("#form").submit(); // submit, as there are no attributes, it will not have an error
$("#name").attr(rules); // add it again so you can validate it
});
答案 3 :(得分:2)
此功能可以通过focusCleanup: true
选项并在所需元素上触发focusin
事件。但是并不总是希望触发这个事件。显然,您可以使用在focusin
上运行的插件内部代码,并在外部调用它,如下所示:
/*get your element and containing validated form*/
var $that = $('#desired_elemenet');
var $form = $that.closest('form');
/*get validator object for the form*/
var validator = $form.validate();
/*use internal code of a plugin to clear the field*/
if (validator.settings.unhighlight) {
validator.settings.unhighlight.call( validator, $that[0], validator.settings.errorClass, validator.settings.validClass );
}
validator.hideThese( validator.errorsFor( $that[0] ) );
答案 4 :(得分:0)
var form = $('#form');
var validator = form.validate();
// Validate single field from that form.
var myfield = $('#myfield');
myfield.removeData('previousValue').removeAttr('aria-invalid');
validator.resetElements(myfield);
答案 5 :(得分:0)
您可以使用
$("#selector").removeClass("error");
$("#selector-error").remove();