gpt4 book ai didi

javascript - 使用选项 ID 选择

转载 作者:行者123 更新时间:2023-12-02 17:55:27 28 4
gpt4 key购买 nike

<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;

FIDDLE

编辑:

如果选项有值,您只需将选择值设置为选项值之一

document.getElementById("editSkillList").value = document.getElementById('4').value;

关于javascript - 使用选项 ID 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20988920/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com