2

我试图忽略使用 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"
    } ); 
});
4

2 回答 2

3

在忽略选项内部有换行符是问题所在:

jsFiddle

$(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"
    } ); 
});
于 2012-08-14T21:32:36.003 回答
1

您可以使用这种更简单的方法从元素中删除远程验证: $('#myfield').rules('remove', 'remote');

于 2016-07-10T05:24:48.387 回答