2 回答
TA贡献1900条经验 获得超5个赞
你可以使用:
mySelect.options[mySelect.selectedIndex].text;
像这样的东西:
function myFunction() {
var mySelect = document.getElementById("mySelect");
document.getElementById("demo").innerHTML = mySelect.value;
document.getElementById("demo1").innerHTML = mySelect.options[mySelect.selectedIndex].text;
}
<div>
<select id="mySelect">
<option value="1">Apple</option>
<option value="2">Orange</option>
<option value="3">Pineapple</option>
<option value="4">Banana</option>
</select>
<p>Click the button to return the value of the selected fruit.</p>
<button type="button" onclick="myFunction()">Try it</button>
<p id="demo"></p>
<p id="demo1"></p>
</div>
TA贡献1752条经验 获得超4个赞
var e = document.getElementById("my_Select");
var value = e.value;
var text = e.options[e.selectedIndex].text;
添加回答
举报