如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
$("#yourdropdownid option:selected").text();
其他回答
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/
这对我来说很有用:
$("#city :selected").text();
我正在使用jQuery 1.10.2
试试看:
$("#myselect :selected").text();
对于ASP.NET下拉列表,可以使用以下选择器:
$("[id*='MyDropDownId'] :selected")
用于获取所选值
$('#dropDownId').val();
要获取所选项目文本,请使用此行:
$("#dropDownId option:selected").text();
对于所选项目的文本,请使用:
$('select[name="thegivenname"] option:selected').text();
对于所选项目的值,请使用:
$('select[name="thegivenname"] option:selected').val();