如何从jQuery的下拉列表中获取所选文本(而不是所选值)?
当前回答
使用此
const select = document.getElementById("yourSelectId");
const selectedIndex = select.selectedIndex;
const selectedValue = select.value;
const selectedText = select.options[selectedIndex].text;
然后在selectedValue和selectedText中获取所选值和文本。
其他回答
用于获取所选值
$('#dropDownId').val();
要获取所选项目文本,请使用此行:
$("#dropDownId option:selected").text();
这对我来说很有用:
$("#city :selected").text();
我正在使用jQuery 1.10.2
这对我有用:
$('#yourdropdownid').find('option:selected').text();
jQuery版本:1.9.1
$("#dropdownid").change(function(el) {
console.log(el.value);
});
或者你可以用这个
$("#dropdownid").change(function() {
console.log($(this).val());
});
Try
dropdown.selectedOptions[0].text
函数read(){console.log(下拉列表.selectedOptions[0].text);}<select id=“下拉列表”><option value=“1”>第一个</option><option value=“2”>秒</option></选择><button onclick=“read()”>read</button>