编程教程 - 技术改变世界
编程教程提供了 JS 在线测试工具,可在线测试 JavaScript 代码,你可以在代码编辑器中输入 JavaScript 代码并点击运行查看结果。
源代码
点击运行
<!DOCTYPE html> <html> <body> <h1>template 元素</h1> <p>单击下面的按钮,显示 template 元素中的隐藏内容。</p> <button onclick="showContent()">显示隐藏的内容</button> <template> <h2>Flower</h2> <img src="/i/photo/flower.gif" width="180" height="180"> </template> <script> function showContent() { var temp = document.getElementsByTagName("template")[0]; var clon = temp.content.cloneNode(true); document.body.appendChild(clon); } </script> </body> </html>
运行结果