概要:5 请设计一套方案,用于确保页面中JS加载完全。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 var n = document.createElement("script"); n
腾讯web前端开发笔试题和答案,标签:笔试大全,http://www.88haoxue.com5 请设计一套方案,用于确保页面中JS加载完全。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
var n = document.createElement("script"); n.type = "text/javascript"; //以上省略部分代码 //ie支持script的readystatechange属性 if(ua.ie){ n.onreadystatechange = function(){ var rs = this.readyState; if('loaded' === rs || 'complete'===rs){ n.onreadystatechange = null; f(id,url); //回调函数 } }; //省略部分代码 //safari 3.x supports the load event for script nodes(DOM2) n.addEventListener('load',function(){ f(id,url); }); //firefox and opera support onload(but not dom2 in ff) handlers for //script nodes. opera, but no ff, support the onload event for link //nodes. }else{ n.onload = function(){ f(id,url); }; } |
上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页
上一篇:华诺集团笔试题
最新更新