如何使用jquery获取选定选项的文本? [英] How to get the text of the selected option of a select using jquery?
本文介绍了如何使用jquery获取选定选项的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有这个选择:
<select id="days">
<option value="0">Today</option>
<option value="1">Yesterday</option>
<option value="7">Last week</option>
</select>
有人选择'上周'的第三个选项,我可以得到上周的价值(其中是7),使用 $(#days)。val()
,但我怎样才能获得文本的值,即上周?
and someone selects the 3rd option 'last week', I can get the value of last week (which is 7), using $("#days").val()
, but how can I get the value of the text i.e 'Last week'?
推荐答案
$("#days option:selected").text()
这篇关于如何使用jquery获取选定选项的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文