运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗/亮
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The firstChild Property</h2> <p>Click the button to get the text of the first child node of the select element.</p> <p><button onclick="myFunction()">Try it</button></p> <select id="mySelect" size="4"><option>Audi</option><option>BMW</option><option>Saab</option><option>Volvo</option></select> <p id="demo"></p> <script> function myFunction() { let text = document.getElementById("mySelect").firstChild.text; document.getElementById("demo").innerHTML = text; } </script> </body> </html>