Is there a way to check document.ready() if jQuery is not available?
Possible Duplicate:
$(document).ready equivalent without jQuery
I know you can use the window.onload event to make functions run, but is there a way for a script to query if the document is ready or not?
Something like
function update()
{
if( !document.ready() ) // don't do unless document loaded
return ;
}
window.setInterval( 'update();', 100 ) ;
Cannot change the <body> element, and no jQuery/other libraries.
Here you go:
var tid = setInterval( function () {
if ( document.readyState !== 'complete' ) return;
clearInterval( tid );
// do your work
}, 100 );
Read about the document.readyState
property here. I am not sure if all current browsers implement it.
Checkout https://github.com/jakobmattsson/onDomReady
It's more complicated than a few lines! - If you want multiple browser compliance.
该代码可以在所有浏览器中使用
if(window.attachEvent()){
window.attachEvent("onload",load);
}else{
window.addEventListener("load",load,true);
}
function load(){
//Code to execute when the document is loaded.
}
链接地址: http://www.djcxy.com/p/71244.html