源代码:
下载代码
AI 编程工具
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>template 元素</h1> <p>点击按钮显示 template 元素中的隐藏内容。</p> <button onclick="showContent()">显示隐藏内容</button> <template> <h2>logo</h2> <img src="https://static.jyshare.com/libs/images/runoob-logo.png" > </template> <script> function showContent() { var temp = document.getElementsByTagName("template")[0]; var clon = temp.content.cloneNode(true); document.body.appendChild(clon); } </script> </body> </html>
运行结果: