Obm*_*nen 1 javascript syntax jquery
我有一个简单的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();
}
Run Code Online (Sandbox Code Playgroud)
哪个工作正常,但是当我添加width参数时:
function my_function_chosen_o99(){
jQuery(".chzn-select").chosen(width:'95%');
}
Run Code Online (Sandbox Code Playgroud)
它给了我一个错误:
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%");
.............................................|
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题?
你需要传递一个对象作为参数(在内{})
jQuery(".chzn-select").chosen({width:'95%'});
Run Code Online (Sandbox Code Playgroud)