简体   繁体   English

使用示例代码进行JQuery选择时的语法错误

[英]Syntax errors when using example code for JQuery Chosen

I've been using this example code to activate chosen fields 我一直在使用此示例代码来激活选定的字段

<script type="text/javascript">
    var config = {
        '.chosen-select': { "proyects", "users" }, //This is necessary to tell the plugin which select fields will be used in chosen 
        '.chosen-select-deselect': { allow_single_deselect: true },
        '.chosen-select-no-single': { disable_search_threshold: 10 },
    }

    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }
</script>

However I get a complaint about a javascript syntax error on the .chosen-select line that reads: Uncaught SyntaxError: Unexpected token , (In Chrome) and I get SyntaxError: missing : after property id (In IceWeasel) 但是,我在.chosen-select行上收到有关Javascript语法错误的投诉,该行显示为: Uncaught SyntaxError: Unexpected token , (在Chrome中),并且SyntaxError: missing : after property id (在IceWeasel中),我得到SyntaxError: missing : after property id

However I can't figure it out. 但是我不知道。 I can get chosen to work, but I have a lot of trouble doing it. 我可以选择工作,但是这样做很麻烦。 I'm thinking it might be because of this. 我想可能是因为这个原因。

Any idea what is wrong? 知道有什么问题吗?

Objects have their key/value pairs separated by : not , . 对象有自己的键/值对分隔:没有, Change this: 更改此:

{ "proyects", "users" }

To this: 对此:

{ "proyects": "users" }

Correct Your JSON syntax 更正JSON语法

 var config = {
          '.chosen-select' : {'proyects':'users'}, 
    '.chosen-select-deselect'  : {allow_single_deselect:true},
    '.chosen-select-no-single' : {disable_search_threshold:10},
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM