按值设置选择选项“已选择”

◇◆丶佛笑我妖孽 提交于 2020-08-16 17:01:25

问题:

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? 但是当我只知道必须选择的optionvalue时,我怎么能这样做呢?

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!