使用 jQuery 获取所选选项的文本 [英] Get text of the selected option with jQuery
本文介绍了使用 jQuery 获取所选选项的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有一些值的选择框.如何获取选定的选项文本,而不是值?
I have a select box with some values. How do I get the selected options text, not the value?
<select name="options[2]" id="select_2">
<option value="">-- Please Select --</option>
<option value="6" price="0">100</option>
<option value="7" price="0">125</option>
<option value="8" price="0">150</option>
<option value="9" price="0">175</option>
<option value="10" price="0">200</option>
<option value="3" price="0">25</option>
<option value="4" price="0">50</option>
<option value="5" price="0">75</option>
</select>
我试过了:
$j(document).ready(function(){
$j("select#select_2").change(function(){
val = $j("select#select_2:selected").text();
alert(val);
});
});
但它回来了 undefined
.
推荐答案
关闭,可以使用
$('#select_2 option:selected').html()
这篇关于使用 jQuery 获取所选选项的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文