我如何使第一个选项的选择与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")[0].selectedIndex = 0;
其他回答
它只适用于我在最后使用触发器('change'),就像这样:
$("#target option:first").attr('selected','selected').trigger('change');
// remove "selected" from any options that might already be selected
$('#target option[selected="selected"]').each(
function() {
$(this).removeAttr('selected');
}
);
// mark the first option as selected
$("#target option:first").attr('selected','selected');
var firstItem = $(“感兴趣类型”)。(“selectedIndex”道具,0)。瓦尔();
控制台日志(firstItem)。
$("#target")[0].selectedIndex = 0;
Use:
alert($( "#target option:first" ).text());