如何判断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 - (完成)响应内容解析完成,可以在客户端调用了

猜你喜欢

转载自ruanqiangbeyond201208043532.iteye.com/blog/2342389