如何判断js文件是否加载完成

[size=medium][color=red][/color][/size]

 

http://www.jquerycn.cn/a_11412

http://www.jizhuomi.com/software/535.html

 

  1. function include_js(file) {    
  2.       var _doc = document.getElementsByTagName('head')[0];     
  3.       var js = document.createElement('script');     
  4.       js.setAttribute('type''text/javascript');     
  5.       js.setAttribute('src', file);     
  6.       _doc.appendChild(js);     
  7.       if (document.all) { //如果是IE     
  8.             js.onreadystatechange = function () {     
  9.                     if (js.readyState == 'loaded' || js.readyState == 'complete') {     
  10.                       alert('IE6、IE7 support js.onreadystatechange');     
  11.                   }     
  12.            }     
  13.       }     
  14.       else {     
  15.              js.onload = function () {     
  16.                        alert('Firefox、chrome and others support js.onload');     
  17.               }     
  18.        }     
  19. }    
  20.      
  21. include_js('jquery.js');  

 

面加载readyState的五种状态 
原文如下: 
0: (Uninitialized) the send( ) method has not yet been invoked. 
1: (Loading) the send( ) method has been invoked, request in progress. 
2: (Loaded) the send( ) method has completed, entire response received. 
3: (Interactive) the response is being parsed. 
4: (Completed) the response has been parsed, is ready for harvesting.

 

翻译成中文为: 
0 - (未初始化)还没有调用send()方法 
1 - (载入)已调用send()方法,正在发送请求 
2 - (载入完成)send()方法执行完成,已经接收到全部响应内容 
3 - (交互)正在解析响应内容 
4 - (完成)响应内容解析完成,可以在客户端调用了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值