如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
$("option:selected", $("#TipoRecorde")).text()
其他回答
$("#dropdownid option:selected").text();
如果您使用asp.net并编写
<Asp:dropdownlist id="ddl" runat="Server" />
那么你应该使用
$('#<%=ddl.Clientid%> option:selected').text();
这对我来说很有用:
$("#city :selected").text();
我正在使用jQuery 1.10.2
如果要将结果作为列表,请使用:
x=[];
$("#list_id").children(':selected').each(function(){x.push($(this).text());})
使用此
const select = document.getElementById("yourSelectId");
const selectedIndex = select.selectedIndex;
const selectedValue = select.value;
const selectedText = select.options[selectedIndex].text;
然后在selectedValue和selectedText中获取所选值和文本。
试试看:
$("#myselect :selected").text();
对于ASP.NET下拉列表,可以使用以下选择器:
$("[id*='MyDropDownId'] :selected")