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:34

If you want the result as a list, then use:

x=[];
$("#list_id").children(':selected').each(function(){x.push($(this).text());})
查看更多
看风景的人
3楼-- · 2018-12-31 03:34

Simply try the following code.

var text= $('#yourslectbox').find(":selected").text();

it returns the text of the selected option.

查看更多
余生请多指教
4楼-- · 2018-12-31 03:35

For multi-selects:

$("#yourdropdownid :selected").map(function(i, v) { return $.trim($(v).text()); }
查看更多
春风洒进眼中
5楼-- · 2018-12-31 03:37

This works for me:

$('#yourdropdownid').find('option:selected').text();

jQuery version: 1.9.1

查看更多
呛了眼睛熬了心
6楼-- · 2018-12-31 03:37
var e = document.getElementById("dropDownId");
var div = e.options[e.selectedIndex].text;
查看更多
无与为乐者.
7楼-- · 2018-12-31 03:38
$("#dropdownid option:selected").text();

if you use asp.net and write

<Asp:dropdownlist id="ddl" runat="Server" />

then you should use

$('#<%=ddl.Clientid%> option:selected').text();
查看更多
登录 后发表回答