<select size="2">
<option selected="selected">Input your option</option>
<option>Input your option</option>
</select>

使用jQuery优雅地取消选项的最佳方法是什么?


当前回答

这个代码适用于我。

$("option:selected").prop("selected", false);

其他回答

$("#selectID option:selected").each(function(){
  $(this).removeAttr("selected");
});

这将遍历每个项目,只取消选中的项目

非常感谢你的解决方案。

单选组合列表的解决方案非常有效。这是我在很多网站上搜索后发现的。

$("#selectID").attr('selectedIndex', '-1').children("option:selected").removeAttr("selected");

另一种简单的方法:

$ (" # selectedID”)[0 - 9]。选择= -1

$(option).removeAttr('selected') //replace 'option' with selected option's selector

在你的选择中设置一个id,像这样: <select id="foo" size="2">

然后你可以使用: $ (" # foo”)。道具(“selectedIndex”,0).change ();