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


当前回答

只需尝试以下代码。

var text= $('#yourslectbox').find(":selected").text();

它返回所选选项的文本。

其他回答

对于多选:

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

这里张贴的答案,例如,

$('#yourdropdownid option:selected').text();

对我来说没用,但这样做了:

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

它可能是jQuery的旧版本。

这对我有用:

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

jQuery版本:1.9.1

var e = document.getElementById("dropDownId");
var div = e.options[e.selectedIndex].text;

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

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