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

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

当前回答

你可以试试这个

$("#target").prop("selectedIndex", 0);

其他回答

你可以试试这个

$("#target").prop("selectedIndex", 0);

Use:

$("#selectbox option:first").val()

请在这个JSFiddle中找到工作简单。

当你使用

$("#target").val($("#target option:first").val());

如果第一个选项值为空,这将在Chrome和Safari中不起作用。

我更喜欢

$("#target option:first").attr('selected','selected');

因为它可以在所有浏览器中工作。

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

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

...

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

就像这样简单:

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