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

2017-06-19 10:58:00
admin
原创
352
<!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>
文章分类
联系我们
电话: 18902328227
Email: 2689701946@qq.com
QQ: 2689701946
微信: 18902328227
地址: 广州番禺区繁华路
  • 在线客服
  • 关注微信
  • 联系电话
    • 欢迎咨询
    • 欢迎加入QQ群 303257430
  • 公众号:源宝网络
    • 联系电话及微信号 18902328227