Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何获取当前<select>文本?我的意思是,如果我选择了<option name="me">ME</option>如何获取其文本?
<select>
<option name="me">ME</option>
因为我正在尝试的方式,返回里面的所有文本<select>
$('#action').change(function() { console.log($(this).text()); //this returns all the texts inside select
试试这个
$('#action').change(function() { $(this).find(':selected').text(); });
$("#" + $(this).attr("id") + " option:selected").text();
也可以!但请使用丹麦的解决方案!
您可以通过使用获取选择的文本
$("#action option:selected").text();