如何获取下拉列表选定值的文本? [英] How to get the text of the selected value of a dropdown list?
本文介绍了如何获取下拉列表选定值的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
jQuery 获取特定选项标签文本
如何获取使用 jquery 选择的选定选项的文本?
我有一个下拉列表,我想知道所选项目的文本.例如:
I have a dropdown list and I want to know the text of the selected item. For example:
<select>
<option value="1">Volvo</option>
<option value="2">Saab</option>
<option value="3">Mercedes</option>
</select>
如果我知道选定的值,我怎样才能得到它的文本值?例如,如果值为 1
,我如何获得 Volvo
?
If I know the selected value, how can I get it's text value? For instance, if the value is 1
how can I get Volvo
?
非常感谢帮助.
推荐答案
您可以使用 option:selected
来获取 select
元素的选中选项,然后 option:selected
code>text() 方法:
You can use option:selected
to get the chosen option of the select
element, then the text()
method:
$("select option:selected").text();
这是一个例子:
console.log($("select option:selected").text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<select>
<option value="1">Volvo</option>
<option value="2" selected="selected">Saab</option>
<option value="3">Mercedes</option>
</select>
这篇关于如何获取下拉列表选定值的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文