如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
$(“#DropDownID”).val()将给出选定的索引值。
其他回答
只需尝试以下代码。
var text= $('#yourslectbox').find(":selected").text();
它返回所选选项的文本。
试试看:
$("#myselect :selected").text();
对于ASP.NET下拉列表,可以使用以下选择器:
$("[id*='MyDropDownId'] :selected")
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").change(function() {
alert($(this).find("option:selected").text());
});
如果元素是动态创建的
$(document).on("change", "#dropdownid", function() {
alert($(this).find("option:selected").text());
});
这段代码对我有用。
$("#yourdropdownid").children("option").filter(":selected").text();