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


当前回答

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

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

其他回答

试试看:

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

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

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

对于所选项目的文本,请使用:

$('select[name="thegivenname"] option:selected').text();

对于所选项目的值,请使用:

$('select[name="thegivenname"] option:selected').val();
$("#dropdownid").change(function(el) {
    console.log(el.value);
});

或者你可以用这个

$("#dropdownid").change(function() {
    console.log($(this).val());
});

只需添加以下行

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

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

这对我来说很有用:

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

我正在使用jQuery 1.10.2