Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript解析jQuery参数_Javascript_Function_Parameters - Fatal编程技术网

Javascript解析jQuery参数

Javascript解析jQuery参数,javascript,function,parameters,Javascript,Function,Parameters,我正在使用一个jQuery插件,它接受一个用户参数,可以容纳多个用户,如: $(elem).thePlugin({ user: [{name: 'username1', image: 'image1.jpg'}, {name: 'username2', image: 'image2.jpg'}] }); 但我希望动态构建用户参数,以便可以执行以下操作: var userparam; $('table.user tr').each(function() { $name

我正在使用一个jQuery插件,它接受一个用户参数,可以容纳多个用户,如:

$(elem).thePlugin({
  user: [{name: 'username1', image: 'image1.jpg'},
         {name: 'username2', image: 'image2.jpg'}]
});
但我希望动态构建用户参数,以便可以执行以下操作:

var userparam;

$('table.user tr').each(function() {
  $name = $('td.name', this).html();
  $image = $('td.img', this).html();

  // add name and image to userparam
});

$(elem).thePlugin({
  user: userparam
});
如何构建userparam变量

var userparam = [];

$('table.user tr').each(function() {
  $name = $('td.name', this).html();
  $image = $('td.img', this).html();

  // add name and image to userparam
  userparam.push({ "name":$name, "image": $image });
});

$(elem).thePlugin({
  user: userparam
});