Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript FF在document.write()之后继续旋转 函数fn(){ 写下“你好!!!”; } 点击_Javascript - Fatal编程技术网

Javascript FF在document.write()之后继续旋转 函数fn(){ 写下“你好!!!”; } 点击

Javascript FF在document.write()之后继续旋转 函数fn(){ 写下“你好!!!”; } 点击,javascript,Javascript,单击按钮后,FF继续旋转(11.0),而好像我直接调用fn(),而不将其连接到按钮,它工作正常。有人可以查看一下吗?您需要调用文档。写入调用文档。如果文档尚未打开,则打开。只要不使用document.close再次关闭文档,浏览器将指示页面可能会更改 <html> <head> <script type="text/javascript" > function fn() { document.write("Hello t

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

您需要调用<代码>文档。写入调用
文档。如果文档尚未打开,则打开
。只要不使用
document.close再次关闭文档,浏览器将指示页面可能会更改

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

    </script>
  </head>

   <body>
      <button onclick="fn()">click</button>
   </body>
</html>

谢谢..但是在我提到的第二个例子中,(在这里我直接调用fn(不点击按钮),为什么它工作良好,不调用文档。关闭?FF自上而下解释网站。当FF到达脚本时,文档仍然打开,并且“你好”将被添加到文档中。呈现完所有内容后,FF调用
document.close()
implicit。这就是加载指示器逐渐消失的原因。那么在我单击按钮的另一种情况下会发生什么呢?类似的情况会发生:Firefox呈现页面->隐式调用
document.close()
->您按下按钮->隐式调用
document.open()
->
document.write(“你好!!!”)
。在
document.write()之后缺少的
document.close()
会导致旋转。不过,即使调用document.close()…CMD+R,重新加载也会停止工作。
function fn() {
    // implicit call to `document.open();` before document.write
    document.write("Hello there!!!");
    document.close();
}