编辑下面的代码:【加编码】
<html> <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>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂