代码道歉,我刚刚开始:)
我正在使用jquery验证插件,它工作正常,但它只会自动更新(即在键入时显示内联错误消息),之后我通过按Tab键离开了一个字段然后返回到它。
当我按Tab键转到新字段时,验证会启动并显示任何错误,然后我可以返回该字段,然后在每次按键后自动开始更新。
为什么没有出去就没有工作呢?
这是我的jquery代码:
<script>
jQuery.validator.addMethod("containNumber", function(value, element) {
return this.optional(element) || (/\d/.test(value));
}, "Password must contain a number");
jQuery.validator.addMethod("containUpper", function(value, element) {
return this.optional(element) || (/[A-Z]/.test(value));
}, "Password must contain an uppercase character");
jQuery.validator.addMethod("containLower", function(value, element) {
return this.optional(element) || (/[a-z]/.test(value));
}, "Password must contain a lowercase character");
$( "#passwordchange" ).validate({
rules: {
password1: {
required: true,
minlength: 8,
maxlength: 64,
containNumber : true,
containUpper: true,
containLower: true
},
password2: {
equalTo: '#password1'
}
}
});
</script>