Get selected text from a drop-down list (select bo

2018-12-31 02:32发布

How can I get the selected text (not the selected value) from a drop-down list in jQuery?

30条回答
妖精总统
2楼-- · 2018-12-31 03:23
$("select[id=yourDropdownid] option:selected").text()

This works fine

查看更多
余欢
3楼-- · 2018-12-31 03:24

For those who are using SharePoint lists and don't want to use the long generated id, this will work:

var e = $('select[title="IntenalFieldName"] option:selected').text();
查看更多
浅入江南
4楼-- · 2018-12-31 03:24

This work for me:

$("#city :selected").text();

I'm using jQuery 1.10.2

查看更多
初与友歌
5楼-- · 2018-12-31 03:25

If you already have the dropdownlist available in a variable, this is what works for me:

$("option:selected", myVar).text()

The other answers on this question helped me, but ultimately the jQuery forum thread $(this + "option:selected").attr("rel") option selected is not working in IE helped the most.

Update: fixed the above link

查看更多
无与为乐者.
6楼-- · 2018-12-31 03:26

Various ways

1. $("#myselect option:selected").text();

2. $("#myselect :selected").text();

3. $("#myselect").children(":selected").text();

4. $("#myselect").find(":selected").text();
查看更多
查无此人
7楼-- · 2018-12-31 03:26

Select Text and selected value on dropdown/select change event in jQuery

$("#yourdropdownid").change(function() {
    console.log($("option:selected", this).text()); //text
    console.log($(this).val()); //value
})
查看更多
登录 后发表回答