如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
试试看:
$("#myselect :selected").text();
对于ASP.NET下拉列表,可以使用以下选择器:
$("[id*='MyDropDownId'] :selected")
其他回答
对于正在使用SharePoint列表且不想使用长时间生成的id的用户,这将起作用:
var e = $('select[title="IntenalFieldName"] option:selected').text();
Use:
('#yourdropdownid').find(':selected').text();
如果变量中已经有下拉列表,这对我很有用:
$("option:selected", myVar).text()
这个问题的其他答案对我有帮助,但最终jQuery论坛线程$(this+“option:selected”).attr(“rel”)选项在IE中不起作用帮助最大。
更新:修复了上述链接
$(“#DropDownID”).val()将给出选定的索引值。
$("select[id=yourDropdownid] option:selected").text()
这很好