javascript 当 document.readystate==complete 与 onload 触发时相同吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4817682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 14:57:59  来源:igfitidea点击:

When document.readystate==complete is that the same when onload fires?

javascriptinternet-explorerjavascript-events

提问by GeorgeU

In internet explorer, when onreadystatechange is fired, and readystate switches to complete, is that the same time onload event triggers?Have all the requests completed by this time?

在Internet Explorer中,当onreadystatechange被触发,readystate切换到完成时,是不是同时触发了onload事件?此时所有的请求都完成了吗?

采纳答案by David Tang

document.onreadystatechangeis typically more optimal than window.onloadas it fires before all external resources such as images are loaded. However, it's not well supported at the moment (but if you're only concerned with IE, then it's not a problem).

document.onreadystatechange通常比window.onload在加载所有外部资源(例如图像)之前触发时更优化。但是,目前它的支持并不好(但如果您只关心 IE,那么这不是问题)。

See: https://developer.mozilla.org/en/DOM/document.onreadystatechange

请参阅:https: //developer.mozilla.org/en/DOM/document.onreadystatechange

Or, for IE: http://msdn.microsoft.com/en-us/library/ms536957(v=vs.85).aspx

或者,对于 IE:http: //msdn.microsoft.com/en-us/library/ms536957(v= vs.85).aspx

回答by Kris Ivanov

document.readyStateis a property and window.onloadis an event

document.readyState是一个属性并且window.onload是一个事件

http://www.w3schools.com/jsref/prop_doc_readystate.asp

http://www.w3schools.com/jsref/prop_doc_readystate.asp

http://www.w3schools.com/js/js_events.asp

http://www.w3schools.com/js/js_events.asp