jQuery获取特定的选项标签文本 [英] jQuery get specific option tag text

查看:94
本文介绍了jQuery获取特定的选项标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有这个:

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

如果我想要获得选项B的值为 2'?

What would the selector look like if I wanted to get "Option B" when I have the value '2'?

请注意,这不是要求如何获取选定的文本值,而只是其中任何一个,无论是选择还是不,取决于值属性。我试过:

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. I tried:

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

但它不工作。

推荐答案

它正在寻找id 列表的元素,其中有一个属性 value 到2.你想要的是列表选项

It's looking for an element with id list which has a property value equal to 2. What you want is the option child of the list.

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

这篇关于jQuery获取特定的选项标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆