按值設置選擇選項「已選擇」 - Set select option 'selected', by value

問題:

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時,我怎麼能這樣作呢? this

I have the following HTML: 我有如下HTML: spa

<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? 如何才能作到這一點? .net

Here's a demo page: http://jsfiddle.net/9Stxb/ 這是一個演示頁面: http//jsfiddle.net/9Stxb/ code


解決方案:

參考一: https://stackoom.com/question/tzGo/按值設置選擇選項-已選擇
參考二: https://oldbug.net/q/tzGo/Set-select-option-selected-by-value
相關文章
相關標籤/搜索