编辑下面的代码:【加编码】
<html> <body> <form id="myForm"> <fieldset> <legend id="myLegend">Personalia:</legend> 用户名: <input type="text"><br> Email: <input type="text"> </fieldset> </form> <p>点击“尝试一下”按钮返回 legend 所属的表单的 id。</p> <p id="demo"></p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction() { var x = document.getElementById("myLegend").form.id; document.getElementById("demo").innerHTML=x; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂