JS设置option为selected状态可通过selectedIndex属性来实现。
<select id="mySelect"> <option value="option1">Option 1</option> <option value="option2">Option 2</option> <option value="option3">Option 3</option> </select> <script> // 设置第三个选项(索引从0开始)为选中状态 document.getElementById('mySelect').selectedIndex = 2; </script>
<select id="mySelect">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
<script>
// 设置第三个选项(索引从0开始)为选中状态
document.getElementById('mySelect').selectedIndex = 2;
</script>