码迷,mamicode.com
首页 > Web开发 > 详细

jQuery的domReady

时间:2015-02-25 23:33:50      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

<!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>

 

jQuery的domReady

标签:

原文地址:http://www.cnblogs.com/samwu/p/4300386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!