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


当前回答

以下内容对我有用:

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

其他回答

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

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

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

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

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

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

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

Try

dropdown.selectedOptions[0].text

函数read(){console.log(下拉列表.selectedOptions[0].text);}<select id=“下拉列表”><option value=“1”>第一个</option><option value=“2”>秒</option></选择><button onclick=“read()”>read</button>

$(“#DropDownID”).val()将给出选定的索引值。