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


当前回答

只需尝试以下代码。

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

它返回所选选项的文本。

其他回答

以下内容对我有用:

$.trim($('#dropdownId option:selected').html())

Use:

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

各种方式

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

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

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

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

对于多选:

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