替换当前文档

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function createNewDoc()
  5. {
  6. var newDoc=document.open("text/html","replace");
  7. var txt="<html><body>学习 DOM 非常有趣!</body></html>";
  8. newDoc.write(txt);
  9. newDoc.close();
  10. }
  11. </script>
  12. </head>
  13.  
  14. <body>
  15. <input type="button" value="打开并写入一个新文档" onclick="createNewDoc()">
  16. </body>
  17.  
  18. </html>