用document.onreadystatechange的方法來監聽狀態改變,
然後用document.readyState == “complete”判斷是否加載完成
代碼如下:
復制代碼 代碼如下:
document.onreadystatechange = subSomething;//當頁面加載狀態改變的時候執行這個方法.
function subSomething()
{
if(document.readyState == “complete”) //當頁面加載狀態
myform.submit(); //表單提交
}
頁面加載readyState的五種狀態 原文如下:
0: (Uninitialized) the send( ) method has not yet been invoked.
1: (Loading) the send( ) method has been invoked, request in progress.
2: (Loaded) the send( ) method has completed, entire response received.
3: (Interactive) the response is being parsed.
4: (Completed) the response has been parsed, is ready for harvesting.
翻譯成中文為:
0 - (未初始化)還沒有調用send()方法
1 - (載入)已調用send()方法,正在發送請求
2 - (載入完成)send()方法執行完成,已經接收到全部響應內容
3 - (交互)正在解析響應內容
4 - (完成)響應內容解析完成,可以在客戶端調用了