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


当前回答

这对我来说很有用:

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

我正在使用jQuery 1.10.2

其他回答

对于正在使用SharePoint列表且不想使用长时间生成的id的用户,这将起作用:

var e = $('select[title="IntenalFieldName"] option:selected').text();

对于多选:

$("#yourdropdownid :selected").map(function(i, v) { return $.trim($(v).text()); }

如果要将结果作为列表,请使用:

x=[];
$("#list_id").children(':selected').each(function(){x.push($(this).text());})

只需添加以下行

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

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

$("#dropdownID").change(function(){
  alert($('option:selected', $(this)).text());
});