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


当前回答

试试看:

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

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

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

其他回答

只需添加以下行

$(this).prop('selected', true);

将.att替换为.prop,它适用于所有浏览器。

var e = document.getElementById("dropDownId");
var div = e.options[e.selectedIndex].text;
$("#yourdropdownid option:selected").text();

使用此

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

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

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

这对我来说很有用:

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

我正在使用jQuery 1.10.2