最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SyntaxError: missing : after property id when using jQuery - Stack Overflow

programmeradmin0浏览0评论

Why do I get the following error when doing the following inside the jQuery validation plugin by bassistance? IMO this should have worked, but I get this:

SyntaxError: missing : after property id

var type = $(this).type; //This is a hidden field in the form 


$("#myForm").validate({

    var type = $(this).type;
    rules: {
        name: {
            required: true,
            minlength: 3,
            maxlength: 51
        },
    },

Why do I get the following error when doing the following inside the jQuery validation plugin by bassistance? IMO this should have worked, but I get this:

SyntaxError: missing : after property id

var type = $(this).type; //This is a hidden field in the form 


$("#myForm").validate({

    var type = $(this).type;
    rules: {
        name: {
            required: true,
            minlength: 3,
            maxlength: 51
        },
    },
Share Improve this question edited Dec 24, 2013 at 4:52 Vishal Suthar 17.2k3 gold badges62 silver badges108 bronze badges asked Dec 24, 2013 at 4:40 NormanNorman 6,36525 gold badges91 silver badges148 bronze badges 1
  • Like any other jQuery plugin method, you can only pass key:value pairs separated by mas inside of the .validate() method. The allowed keys and their acceptable values are pre-defined by the plugin developer. I guess you skipped the docs. jqueryvalidation/validate – Sparky Commented Dec 25, 2013 at 16:06
Add a ment  | 

1 Answer 1

Reset to default 4

It's because the validate method accepts object, yet you did not pass an object, try

$("#myForm").validate({

type : $(this).type,
rules: {
    name: {
        required: true,
        minlength: 3,
        maxlength: 51
    },
发布评论

评论列表(0)

  1. 暂无评论