安科网
源代码:
点击运行
<!DOCTYPE html> <html> <body> <p>点击按钮创建 OPTGROUP 元素。</p> <button onclick="myFunction()">尝试一下</button> <select id="mySelect" size="6"> <option>BMW <option>Mercedes <option>Ford <option>Volvo <option>Toyota </select> <script> function myFunction() { var x = document.getElementById("mySelect"); var y = document.createElement("OPTGROUP"); y.setAttribute("label", "SwedishCars"); y.appendChild(x.options[3]) x.insertBefore(y,x.options[3]); } </script> </body> </html>
运行结果
Copyright © 2013 - 2019 Ancii.com All Rights Reserved
京ICP备18063983号-5
京公网安备11010802014868号