源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <iframe src="//www.248k.com/html/html-tutorial.html" style="height:380px;width:520px;"></iframe> <p>点击以下按钮获取 iframe 中 h1 节点,并显示在本页中。</p> <p><strong>注意:</strong> Internet explorer 8 及更早 IE 版本支持该方法。</p> <button onclick="myFunction()">点我</button> <script> function myFunction() { var frame = document.getElementsByTagName("IFRAME")[0] var h = frame.contentWindow.document.getElementsByTagName("H1")[0]; var x = document.adoptNode(h); document.body.appendChild(x); } </script> </body> </html>
运行结果: