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

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

当前回答

对我来说,只有当我添加下面这行代码时,它才能工作

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

其他回答

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

就像这样简单:

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

以下是我的做法:

$("#target option")
    .removeAttr('selected')
    .find(':first')     // You can also use .find('[value=MyVal]')
        .attr('selected','selected');

如果您有禁用选项,您可以添加not([disabled])以防止选择它们,结果如下:

$("#target option:not([disabled]):first").attr('selected','selected')

Use:

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

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