1

我有一个简单的 javascript/jquery 函数:

jQuery(document).ajaxSuccess(function(e, xhr, settings) {
   var widget_id_base = '099_cf_samurai_widget';

   if(settings.data.search('action=save-widget') != -1 &&
        settings.data.search('id_base=' + widget_id_base) != -1) {
         my_function_chosen_o99();
   }
}); 

function my_function_chosen_o99(){
   jQuery(".chzn-select").chosen();
}

哪个工作正常,但是当我添加宽度参数时:

function my_function_chosen_o99(){
   jQuery(".chzn-select").chosen(width:'95%');
}

它给了我一个错误:

Error: SyntaxError: missing ) after argument list
Source File: http://localhost/my-path/js/o99.chosen.init.js?ver=k99
Line: 20, Column: 41
Source Code:
      jQuery(".chzn-select").chosen(width:"95%"); 
.............................................|

这段代码有什么问题?

4

1 回答 1

9

您需要传递一个对象作为参数(在{}

 jQuery(".chzn-select").chosen({width:'95%'});
于 2013-11-13T15:50:13.437 回答