如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
var e = document.getElementById("dropDownId");
var div = e.options[e.selectedIndex].text;
其他回答
这对我有用
$("#dropdownid").change(function() {
alert($(this).find("option:selected").text());
});
如果元素是动态创建的
$(document).on("change", "#dropdownid", function() {
alert($(this).find("option:selected").text());
});
对于多选:
$("#yourdropdownid :selected").map(function(i, v) { return $.trim($(v).text()); }
以下内容对我有用:
$.trim($('#dropdownId option:selected').html())
这段代码对我有用。
$("#yourdropdownid").children("option").filter(":selected").text();
$("#dropdownid").change(function(el) {
console.log(el.value);
});
或者你可以用这个
$("#dropdownid").change(function() {
console.log($(this).val());
});