运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> Select your favorite car: <br> <select id="mySelect" size="4"> <option label="Volvo">Volvo (Latin for "I roll")</option> <option label="Saab">Saab (Swedish Aeroplane AB)</option> <option label="Mercedes">Mercedes (Mercedes-Benz)</option> <option label="Audi">Audi (Auto Union Deutschland Ingolstadt)</option> </select> <p>Click the button to return the label value of the selected car.</p> <button type="button" onclick="myFunction()">Try it</button> <script> function myFunction() { var x = document.getElementById("mySelect").selectedIndex; alert(document.getElementsByTagName("option")[x].label); } </script> </body> </html>