執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
前往 Spaces
<!DOCTYPE html> <html> <body> <h3>A demonstration of how to access an OPTGROUP element</h3> <select size="4"> <optgroup id="myOptgroup" label="Swedish Cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="koenigsegg">Koenigsegg</option> </optgroup> </select> <p>Click the button to get the label/description of the option group.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myOptgroup").label; document.getElementById("demo").innerHTML = x; } </script> </body> </html>