2013-07-03 45 views
2
<head> 
    <script type="text/javascript"> 

     document.onreadystatechange = WaitForComplete; 

     function WaitForComplete() { 
      console.log ("The state of the document: " + document.readyState); 
     } 

     function OnLoad() { 
      console.log ("The document has been loaded."); 
     } 
    </script> 
</head> 
<body onload="OnLoad()"> 
</body> 

在firefox->控制檯與readyState的一些代碼,它表明:試圖瞭解JS

The state of the document: interactive 
The state of the document: complete 
The document has been loaded. 

問:

爲什麼每次我在Firefox上運行腳本,那隻能說明interactivecomplete?如何對其他國家:由於您使用的是onreadystatechange功能,而不是檢查上兩種狀態uninitialized,loading...uninitializedloading ...

回答

0

你沒有得到的狀態。

onreadystatechange在文檔處於交互式或完成狀態時工作,並且在加載或未初始化的狀態下它不會調用。

來得到你需要添加代碼的加載狀態:

document.write(document.readyState);

在腳本的起點不使用onreadystatechange

而且uninitialized表示您不能執行任何JavaScript並且無法獲得該狀態。