运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 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>