Jquery验证脚本错误

时间:2011-10-20 22:49:49

标签: php jquery jquery-validate

这是一个真正令人尴尬的问题。我有一个验证脚本问题,我不知道为什么。 Firebug告诉我jquery已加载,validation.js已加载,Jquery UI已加载且一切正常。该脚本位于一个包含的js页面上并被加载。(如果脚本在php文件中或包含在内,则会发生同样的事情.Jquery 1.6.4

我从firebug得到的错误是:     属性列表发布后缺失}:{

显然那里有}。我在它之前或之后都找不到任何东西会导致这个问题。这个剧本对我来说看起来很完美。

$(function(){             
  $("#postform").validate({
    rules: {
        title:{
            required: true,
            minlength: 8,
            maxlength: 200
        }
        post:{
            required: true,
            minlength: 35
        }
        category: {
            required: true
        }

        date:{
            date: true,
            required: true
        }
        author: {
            required: true,
            minlength: 6,   
            maxlength: 35
        }
    },          
    messages:{
        title:{
            required: "Required input",
            minlength: jQuery.format("At least {8} characters are necessary"),
            maxlength: jQuery.format("No more than {200} characters")
        }
        post:{
            required: "Required input",
            minlength: jQuery.format("At least {35} characters are necessary")
        }
        category: "Please choose a value from the dropdown",

        date: "A date is required",

        author: {
            required: "this field is required",
            maxlength: jQuery.format("No more than {36} characters"),
            minlength: jQuery.format("At least {5} characters are necessary")
        }

    }
});        
});

我正在使用ajax来处理表单,但在我看来,验证首先是不应该的。我知道那很有效。

我还会说,在此之前我有一个不同的设置(在每个名称上添加规则),表单会验证,但即使无效字段无效,仍会发布到数据库。

有什么想法?我已经在这2天了。希望有人在此之前见过这个

2 个答案:

答案 0 :(得分:1)

像这个例子一样修复:

   title:{
        required: true,
        minlength: 8,
        maxlength: 200
    }***,***
    post:{
        required: true,
        minlength: 35
    }

答案 1 :(得分:1)

你遗漏了一串逗号,,完全如下......

  $("#postform").validate({
    rules: {
        title:{
            required: true,
            minlength: 8,
            maxlength: 200
        },
        post:{
            required: true,
            minlength: 35
        },
        category: {
            required: true
        },

        date:{
            date: true,
            required: true
        },
        author: {
            required: true,
            minlength: 6,   
            maxlength: 35
        }
    },          
    messages:{
        title:{
            required: "Required input",
            minlength: jQuery.format("At least {8} characters are necessary"),
            maxlength: jQuery.format("No more than {200} characters")
        },
        post:{
            required: "Required input",
            minlength: jQuery.format("At least {35} characters are necessary")
        },
        category: "Please choose a value from the dropdown",

        date: "A date is required",

        author: {
            required: "this field is required",
            maxlength: jQuery.format("No more than {36} characters"),
            minlength: jQuery.format("At least {5} characters are necessary")
        }
    }
  });