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

延迟加载js文件

时间:2018-08-08 16:42:42      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:function   setattr   body   key   tag   index   class   char   htm   

<!doctype html>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<script>
        setTimeout(function(){ //延迟5秒
            var body = document.getElementsByTagName(‘body‘)[0];
            var scr = document.createElement(‘script‘);//创建一个script节点
            scr.setAttribute(‘src‘,‘test1.js‘); //给script节点添加路径
            body.appendChild(scr);
        },5000);
 
</script>
</body>
</html>

延迟加载js文件

标签:function   setattr   body   key   tag   index   class   char   htm   

原文地址:https://www.cnblogs.com/niuxiaoxian/p/9443639.html

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