執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
前往 Spaces
<!DOCTYPE html> <html> <body> <select id="mySelect"> <option>Apple</option> <option>Orange</option> <option>Pineapple</option> <option>Banana</option> </select> <p>Click the button to select the option element with index "2".</p> <p><b>Note:</b> The index starts at 0.</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { document.getElementById("mySelect").selectedIndex = "2"; } </script> </body> </html>