我如何使第一个选项的选择与jQuery?

<select id="target">
  <option value="1">...</option>
  <option value="2">...</option>
</select>

当前回答

如果你打算使用第一个选项作为默认的

<select>
    <option value="">Please select an option below</option>
    ...

然后你可以使用:

$('select').val('');

它很漂亮,也很简单。

其他回答

如果你要存储select元素的jQuery对象:

var jQuerySelectObject = $("...");

...

jQuerySelectObject.val(jQuerySelectObject.children().eq(0).val());

var firstItem = $(“感兴趣类型”)。(“selectedIndex”道具,0)。瓦尔();

控制台日志(firstItem)。

$("#target")[0].selectedIndex = 0;

就像这样简单:

$('#target option:first').prop('selected', true);
$("#target").val($("#target option:first").val());