2011-06-20 29 views
2

如果我運行這段代碼,爲什麼頁面沒有完成加載?它將始終顯示我的瀏覽器選項卡上的連接。這個網頁爲什麼不完成加載?

這是一個簡單的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> 

回答

4

的Bec因爲你沒有關閉文件。

document.close()

+1

謝謝。有效。沒有意識到需要關閉。 –

+0

@在理論上簡化了您還需要'document.open',但是如果現有文檔已經關閉,則document.write將打開一個新文檔。 – Raynos

+0

謝謝。但從理論上講,通過讓流看起來更加完整? –

相關問題