如何从jQuery的下拉列表中获取所选文本(而不是所选值)?


当前回答

以下内容对我有用:

$.trim($('#dropdownId option:selected').html())

其他回答

试试看:

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

对于ASP.NET下拉列表,可以使用以下选择器:

$("[id*='MyDropDownId'] :selected")

使用此

const select = document.getElementById("yourSelectId");

const selectedIndex = select.selectedIndex;
const selectedValue = select.value;
const selectedText = select.options[selectedIndex].text;   

然后在selectedValue和selectedText中获取所选值和文本。

$("#yourdropdownid option:selected").text();
$("select[id=yourDropdownid] option:selected").text()

这很好

这段代码对我有用。

$("#yourdropdownid").children("option").filter(":selected").text();