编辑下面的代码:【加编码】
<html> <body> <form> <label id="myLabel" for="male">Male</label> <input type="radio" name="sex" id="male" value="male"><br> </form> <p>点击“尝试一下”按钮改变 label 的 for 属性的值。</p> <p id="demo"></p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction() { document.getElementById("myLabel").htmlFor="newValue"; document.getElementById("demo").innerHTML="for 属性的值从 'male' 改为 'newValue'。"; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂