源代码 :
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>开源教程(ossoft.cn)</title> <script> function createDoc(){ var doc=document.open("text/html","replace"); var txt="<!DOCTYPE html><html><body>学习 HTML DOM 很有趣!</body></html>"; doc.write(txt); doc.close(); } </script> </head> <body> <input type="button" value="新文档" onclick="createDoc()"> </body> </html>
运行结果