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