我如何使第一个选项的选择与jQuery?
<select id="target">
<option value="1">...</option>
<option value="2">...</option>
</select>
我如何使第一个选项的选择与jQuery?
<select id="target">
<option value="1">...</option>
<option value="2">...</option>
</select>
当前回答
你可以试试这个
$("#target").prop("selectedIndex", 0);
其他回答
$("#target").val(null);
镀铬加工得很好
如果你打算使用第一个选项作为默认的
<select>
<option value="">Please select an option below</option>
...
然后你可以使用:
$('select').val('');
它很漂亮,也很简单。
虽然每个函数可能都不是必需的…
$('select').each(function(){
$(this).find('option:first').prop('selected', 'selected');
});
对我有用。
var firstItem = $(“感兴趣类型”)。(“selectedIndex”道具,0)。瓦尔();
控制台日志(firstItem)。
$("#target")[0].selectedIndex = 0;