jQuery獲取特定的選項標籤文本 - jQuery get specific option tag text

問題:

All right, say I have this: 好吧,說我有這個: this

<select id='list'>
    <option value='1'>Option A</option>
    <option value='2'>Option B</option>
    <option value='3'>Option C</option>
</select>

What would the selector look like if I wanted to get "Option B" when I have the value '2'? 若是我想得到值「 2」時選擇「選項B」,選擇器會是什麼樣? spa

Please note that this is not asking how to get the selected text value, but just any one of them, whether selected or not, depending on the value attribute. 請注意,這不是在詢問如何獲取選定的文本值,而是詢問其中的任何一個(取決因而否選中),具體取決於value屬性。 I tried: 我試過了: .net

$("#list[value='2']").text();

But it is not working. 但這是行不通的。 code


解決方案:

參考一: https://stackoom.com/question/pAK/jQuery獲取特定的選項標籤文本
參考二: https://oldbug.net/q/pAK/jQuery-get-specific-option-tag-text
相關文章
相關標籤/搜索