如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
$("#dropdownID").change(function(){
alert($('option:selected', $(this)).text());
});
其他回答
对于所选项目的文本,请使用:
$('select[name="thegivenname"] option:selected').text();
对于所选项目的值,请使用:
$('select[name="thegivenname"] option:selected').val();
这对我来说很有用:
$("#city :selected").text();
我正在使用jQuery 1.10.2
$('#id').find('option:selected').text();
对于多选:
$("#yourdropdownid :selected").map(function(i, v) { return $.trim($(v).text()); }
这对我有用
$("#dropdownid").change(function() {
alert($(this).find("option:selected").text());
});
如果元素是动态创建的
$(document).on("change", "#dropdownid", function() {
alert($(this).find("option:selected").text());
});