如果您知道索引、值或文本。如果您没有直接引用的ID。

这、这和这都是有用的答案。

示例标记

<div class="selDiv">
  <select class="opts">
    <option selected value="DEFAULT">Default</option>
    <option value="SEL1">Selection 1</option>
    <option value="SEL2">Selection 2</option>
  </select>
</div>

当前回答

对于Jquery selected,如果您将属性发送到函数并需要更新select选项

$('#yourElement option[value="'+yourValue+'"]').attr('selected', 'selected');
$('#editLocationCity').chosen().change();
$('#editLocationCity').trigger('liszt:updated');

其他回答

试试这个

您只需使用select字段id而不是#id(即#select_name)

使用选择选项值代替选项值

 <script>
    $(document).ready(function() {
$("#id option[value='option value']").attr('selected',true);
   });
    </script>

谢谢你的提问。希望这段代码对您有用。

var val = $("select.opts:visible option:selected ").val();
/* This will reset your select box with "-- Please Select --"   */ 
    <script>
    $(document).ready(function() {
        $("#gate option[value='']").prop('selected', true);
    });
    </script>

使用jquery-2.1.4,我找到了以下适合我的答案:

$('#MySelectionBox').val(123).change();

如果您有字符串值,请尝试以下操作:

$('#MySelectionBox').val("extra thing").change();

其他例子对我来说不起作用,所以我要加上这个答案。

我在以下位置找到了原始答案:https://forum.jquery.com/topic/how-to-dynamically-select-option-in-dropdown-menu

上面的方法都没有提供我需要的解决方案,所以我想我会提供适合我的方法。

$('#element option[value="no"]').attr("selected", "selected");