简单教程
提交运行
代码编辑器:
<form id="myForm" action="/dy/html/getpost"> <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>
运行结果: