Jquery 验证脚本错误

发布于 2024-12-10 19:49:20 字数 1703 浏览 0 评论 0原文

这真是一个令人尴尬的问题。我遇到验证脚本问题,但我不知道为什么。 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天了。希望有人以前见过这个

This is a truly embarrasssing question. I am having a validate script problem and I have no idea why. Firebug tells me jquery is loaded, validation.js is loaded, Jquery UI is loaded and all is well. The script is on a included js page and is loaded.(does the same thing if the script in on the php file or included. Jquery 1.6.4

The error I get from firebug is:
missing } after property list post:{

The } is obviously there. I can find nothing ebfore it or after that would cause this problem. The script looks picture perfect to me.

$(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")
        }

    }
});        
});

I am using ajax to process the form but it seems to me validate comes first so that shouldn't matter. I know that works.

I will also say, that I had a different set up before this (add rules on each name), the form would validate but still post to the DB even with invalid fields invalid.

Any thoughts? I have been on this for 2 days. Hopefully someone has seen this before

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

像这个例子一样修复:

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

fix like this example:

   title:{
        required: true,
        minlength: 8,
        maxlength: 200
    }***,***
    post:{
        required: true,
        minlength: 35
    }
我很OK 2024-12-17 19:49:20

您缺少一堆逗号 , 如下所示......

  $("#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")
        }
    }
  });   

You are missing a bunch of commas , exactly as follows....

  $("#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")
        }
    }
  });   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文