如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
Try:
$var = jQuery("#dropdownid option:selected").val();
alert ($var);
或者要获取选项的文本,请使用text():
$var = jQuery("#dropdownid option:selected").text();
alert ($var);
更多信息:
http://api.jquery.com/val/http://api.jquery.com/text/
其他回答
试试看:
$("#myselect :selected").text();
对于ASP.NET下拉列表,可以使用以下选择器:
$("[id*='MyDropDownId'] :selected")
$("#yourdropdownid option:selected").text();
$("#dropdownID").change(function(){
alert($('option:selected', $(this)).text());
});
这对我有用
$("#dropdownid").change(function() {
alert($(this).find("option:selected").text());
});
如果元素是动态创建的
$(document).on("change", "#dropdownid", function() {
alert($(this).find("option:selected").text());
});
$("select[id=yourDropdownid] option:selected").text()
这很好