对象不支持此操作

时间:2015-04-23 07:31:33

标签: jquery

HTML:

<select id="country" multiple="multiple"><option>Albania</option><option>Bangladesh</option><option>China</option><option>India</option></select>

<a onclick="submit()">submit</a>

JS:

function submit(){
  var selected = [];
  $("#country option:selected").each(function(){
     selected.push($(this).text());
  });
  alert(selected);
}

当我点击提交时,我正在获得&#34;对象不支持此操作&#34;错误!!任何解决方案?

1 个答案:

答案 0 :(得分:2)

问题来自您的提交函数声明:将其替换为

submit = function() {
   ...
}

Here's JSFiddle snippet in which I got your code running