FF在document.write()之后继续旋转

Roh*_*t P 8 javascript

<html>
  <head>
    <script type="text/javascript" >
       function fn() {
       document.write("Hello there!!!");
       }

    </script>
  </head>

   <body>
      <button onclick="fn()">click</button>
   </body>
</html>
Run Code Online (Sandbox Code Playgroud)

单击按钮后,FF继续旋转(11.0),而好像我直接调用fn()而不将其连接到按钮,它工作正常.有人可以看看这个吗?

Zet*_*eta 13

你需要打电话document.close().如果文档尚未打开则document.write调用document.open.只要文档没有再次关闭,document.close浏览器就会指示页面可能会发生变化.

function fn() {
    // implicit call to `document.open();` before document.write
    document.write("Hello there!!!");
    document.close();
}
Run Code Online (Sandbox Code Playgroud)