编辑下面的代码:【加编码】
<html> <body> <h3>访问 LEGEND 元素</h3> <fieldset> <legend id="myLegend">Personalia:</legend> 用户名: <input type="text"> </fieldset> <p>点击按钮获取 legend 元素的文本。</p> <p id="demo"></p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction() { var x = document.getElementById("myLegend").textContent; document.getElementById("demo").innerHTML = x; }; </script> <p><strong>注意:</strong>Internet Explorer 8 及其之前的文本不支持 textContent 属性。</p> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂