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

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


当前回答

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

其他回答

另一种简单的方法:

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

简单的方法

(“select”美元)。瓦尔(”)

我只是在select本身上使用了这个,它做到了。

我使用的是jQuery 1.7.1。

非常感谢你的解决方案。

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

$("#selectID").attr('selectedIndex', '-1').children("option:selected").removeAttr("selected");
$(option).removeAttr('selected') //replace 'option' with selected option's selector

哦,jquery。

既然还没有原生的javascript方法,我觉得有必要提供一个。

var select = document.querySelector('select'); //hopefully you'll use a better selector query
select.selectedIndex = 0; // or -1, 0 sets it to first option, -1 selects no options

为了向你们展示这个有多快,基准测试