如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
以下内容对我有用:
$.trim($('#dropdownId option:selected').html())
其他回答
试试看:
$("#myselect :selected").text();
对于ASP.NET下拉列表,可以使用以下选择器:
$("[id*='MyDropDownId'] :selected")
使用此
const select = document.getElementById("yourSelectId");
const selectedIndex = select.selectedIndex;
const selectedValue = select.value;
const selectedText = select.options[selectedIndex].text;
然后在selectedValue和selectedText中获取所选值和文本。
以下内容对我有用:
$.trim($('#dropdownId option:selected').html())
这段代码对我有用。
$("#yourdropdownid").children("option").filter(":selected").text();
$("#dropdown").find(":selected").text();
$("#dropdown :selected").text();
$(“#下拉选项:selected”).text();
$("#dropdown").children(":selected").text();