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
相关文章
相关标签/搜索