<select id="editSkillList">
<option id="0">Select</option>
<option id="8">text1</option>
<option id="5">text2</option>
<option id="4">text3</option>
</select><br><br>
Javascript代码
document.getElementById("editSkillList").selectedIndex="2";
但是我想使用选项 id 设置选择。这可能吗?那么请帮助我
最佳答案
您只需将选择值设置为定位 ID 后从选项中获取的文本即可
document.getElementById("editSkillList").value = document.getElementById('4').innerText;
编辑:
如果选项有值,您只需将选择值设置为选项值之一
document.getElementById("editSkillList").value = document.getElementById('4').value;
关于javascript - 使用选项 ID 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20988920/