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


当前回答

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

其他回答

这对我来说很有用:

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

我正在使用jQuery 1.10.2

只需添加以下行

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

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

这对我有用

$("#dropdownid").change(function() {
    alert($(this).find("option:selected").text());
});

如果元素是动态创建的

$(document).on("change", "#dropdownid", function() {
    alert($(this).find("option:selected").text());
});

在jQuery中的下拉列表/选择更改事件上选择文本和所选值

$("#yourdropdownid").change(function() {
    console.log($("option:selected", this).text()); //text
    console.log($(this).val()); //value
})

试试看:

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

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

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