这个网页为什么不完成加载?

问题描述:

如果我运行这段代码,为什么页面没有完成加载?它将始终显示我的浏览器选项卡上的连接。这个网页为什么不完成加载?

这是一个简单的javascript,它会提示一个警告框并将整个文档更改为单词测试。

使用Javascript - testQuery.js

(function (window, undefined) { 

var testQuery = function(obj) { 
     if (!(this instanceof testQuery)) { 
      return new testQuery(obj); 
     } 
} 


testQuery.alertMessage = function() { 
     alert("alert"); 
    document.write("testing"); 
}; 

    window.testQuery = testQuery; 

}) (window); 

HTML - testQuery.html

<html> 
<head> 

<script src="testQuery.js"></script> 
<script> 

function onClick() { 

testQuery.alertMessage(); 

} 

</script> 
</head> 

的Bec因为你没有关闭文件。

document.close()

+1

谢谢。有效。没有意识到需要关闭。 –

+0

@在理论上简化了您还需要'document.open',但是如果现有文档已经关闭,则document.write将打开一个新文档。 – Raynos

+0

谢谢。但从理论上讲,通过让流看起来更加完整? –