fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> </head> <body> <form id="myForm" action="form_action.asp"> <input type="radio" name="sex" id="male" value="male"> </form> <p>点击按钮创建 LABEL 元素。</p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction(){ var x = document.createElement("LABEL"); var t = document.createTextNode("Male"); x.setAttribute("for", "male"); x.appendChild(t); document.getElementById("myForm").insertBefore(x,document.getElementById("male")); }; </script> </body> </html>
运行结果