Discuz教程网

js动态加载以及确定加载完成的代码

[复制链接]
authicon dly 发表于 2011-9-14 08:34:21 | 显示全部楼层 |阅读模式
代码如下:
  1. var otherJScipt = document.createElement("script");
  2. otherJScipt = document.createElement("script");
  3. otherJScipt.setAttribute("type", "text/javascript");
  4. otherJScipt.setAttribute("src", "/xxx.js");
  5. document.getElementsByTagName("head")[0].appendChild(otherJScipt);//追加到head标签内


  6. //判断服务器
  7. if (navigator.userAgent.indexOf("IE") >= 0) {
  8. //IE下的事件
  9. otherJScipt.onreadystatechange = function () {
  10. //IE下的判断,判断是否加载完成
  11. if (otherJScipt && (otherJScipt.readyState == "loaded" || otherJScipt.readyState == "complete")) {
  12. otherJScipt.onreadystatechange = null;
  13. callMyFun();
  14. }
  15. };
  16. }
  17. else {
  18. otherJScipt.onload = function () {
  19. otherJScipt.onload = null;
  20. callMyFun();
  21. };
  22. }
复制代码



上一篇:DB.ASP 用Javascript写ASP很灵活很好用很easy
下一篇:代码如下: [code]var otherJScipt = document.createElement("script");
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 08:48

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表