我试图忽略使用jQuery验证插件的表单的“远程”验证属性,因此我可以在提交表单而不是字段的onBlur时启用它。我有以下代码,但我收到语法错误。我该如何解决?
$(document).ready(function()
{
$("#checkNameForm").validate( {
"onkeyup":false,
"rules":{
"Name":{
"required":true,
"minlength":5,
"maxlength":10,
"remote":"\/abc\/def\/checkname"
}
},
"messages":{
"Name":{
"required":"Please enter a Name.",
"remote":"Name is already in use."
}
},
"ignore":"input[
remote
] ",
success:function(label) {
label.addClass("success");
},
"validClass":"success"
} );
});
答案 0 :(得分:3)
在ignore选项中包含换行符是问题:
$(document).ready(function()
{
$("#checkNameForm").validate( {
onkeyup: false,
rules: {
"Name": {
"required":true,
"minlength":5,
"maxlength":10,
"remote":"\/abc\/def\/checkname"
}
},
messages: {
"Name": {
"required":"Please enter a Name.",
"remote":"Name is already in use."
}
},
ignore: "input[remote]",
success: function(label) {
label.addClass("success");
},
"validClass":"success"
} );
});
答案 1 :(得分:1)
您可以使用这种更简单的方法从元素中删除远程验证:
$('#myfield').rules('remove', 'remote');