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

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

当前回答

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

控制台日志(firstItem)。

其他回答

虽然每个函数可能都不是必需的…

$('select').each(function(){
    $(this).find('option:first').prop('selected', 'selected');
});

对我有用。

Use:

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

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

您可以使用它从下拉菜单中选择任何选项。

// 'N' can by any number of option.  // e.g.,  N=1 for first option
$("#DropDownId").val($("#DropDownId option:eq(N-1)").val()); 

这对我很管用!

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

你可以试试这个

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