问题:
I have a select
field with some options in it. 我有一个select
字段,其中包含一些选项。 Now I need to select one of those options
with jQuery. 现在我需要使用jQuery选择其中一个options
。 But how can I do that when I only know the value
of the option
that must be selected? 但是当我只知道必须选择的option
的value
时,我怎么能这样做呢?
I have the following HTML: 我有以下HTML:
<div class="id_100">
<select>
<option value="val1">Val 1</option>
<option value="val2">Val 2</option>
<option value="val3">Val 3</option>
</select>
</div>
I need to select the option with value val2
. 我需要选择值为val2
的选项。 How can this be done? 如何才能做到这一点?
Here's a demo page: http://jsfiddle.net/9Stxb/ 这是一个演示页面: http : //jsfiddle.net/9Stxb/
解决方案:
参考一: https://stackoom.com/question/tzGo/按值设置选择选项-已选择参考二: https://oldbug.net/q/tzGo/Set-select-option-selected-by-value
来源:oschina
链接:https://my.oschina.net/u/4432649/blog/4320927