标签:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>jQuery的DOMready</title> <script> var domReady = function(fn){ var completed = function() { document.removeEventListener( "DOMContentLoaded", completed, false ); window.removeEventListener( "load", completed, false ); fn(); }; // 如果dom已经准备好了,那就开始咯 if ( document.readyState === "complete" ) { setTimeout( domReady,0,fn ); } else { document.addEventListener( "DOMContentLoaded", completed, false ); // 保险起见加个load事件咯 window.addEventListener( "load", completed, false ); } } domReady(function(){ alert(document.querySelectorAll(".test")[0].innerHTML); }); </script> </head> <body> jQuery的DOMready <div class="test">dom ready?</div> </body> <script> </script> </html>
标签:
原文地址:http://www.cnblogs.com/samwu/p/4300386.html