http://jqueryvalidation.org/rules/描述了如何从jQuery验证器添加和删除规则。
如http://jsfiddle.net/h0apn1a1/1/所示,它不会删除“远程”规则。该如何实现?
var validator = $("#myForm").validate({
rules: {
myelement: {
minlength: 2,
maxlength: 4,
required: true,
remote: {
url: "/echo/html/",
type: "POST",
data: {
html: 0,
delay: .5
}
}
}
},
messages: {
myelement: {
remote: "error message"
}
}
});
$('#testit').click(function () {
console.log($('#myelement').rules());
$('#myelement').rules('remove', 'remote');
console.log($('#myelement').rules());
console.log($('#myelement').valid(), validator.element('#myelement'));
})