IE 和Opera 还支持<link>元素上的load 事件,以便开发人员确定样式表是否加载完毕

2017-06-19 10:58:00
admin
原创
585
<!DOCTYPE html>
<html>
<head>
    <title>Load Event Example</title>
    <script type="text/javascript" src="http://code.ybao.org/demo/js/EventUtil.js"></script>
</head>
<body>
    <script type="text/javascript">
        EventUtil.addHandler(window, "load", function(){
        
            var script = document.createElement("script");
            EventUtil.addHandler(script, "load", function(event){
                alert("Loaded");
            });
            script.src = "http://code.ybao.org/demo/js/example.js";
            document.body.appendChild(script);
            
            var link = document.createElement("link");
            link.type = "text/css";
            link.rel= "stylesheet";
            
            //opera only
            EventUtil.addHandler(link, "load", function(event){
                alert("css loaded");
            });
            link.href = "http://code.ybao.org/demo/js/example.css";
            document.getElementsByTagName("head")[0].appendChild(link);
        });
    </script>
</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络