如何从jQuery的下拉列表中获取所选文本(而不是所选值)?


当前回答

如果要将结果作为列表,请使用:

x=[];
$("#list_id").children(':selected').each(function(){x.push($(this).text());})

其他回答

试试看:

$("#myselect :selected").text();

对于ASP.NET下拉列表,可以使用以下选择器:

$("[id*='MyDropDownId'] :selected")

对于所选项目的文本,请使用:

$('select[name="thegivenname"] option:selected').text();

对于所选项目的值,请使用:

$('select[name="thegivenname"] option:selected').val();
$("#dropdownID").change(function(){
  alert($('option:selected', $(this)).text());
});

这对我有用:

$('#yourdropdownid').find('option:selected').text();

jQuery版本:1.9.1

$('#id').find('option:selected').text();