zoukankan      html  css  js  c++  java
  • js动态加载 以及确定加载完成

    利用js动态加载js文件到页面,并在确定加载完成后调用相关function 代码如下:

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

      

  • 相关阅读:
    设置CentOS7 静态获取IP
    视图与索引
    常用sql语句--DQL
    数据完整性
    常用sql语句--DML
    常用数据类型
    常用sql语句--DDL
    命令提示符内简单操作MySQL
    cnpm安装教程
    js生成指定范围的随机整数
  • 原文地址:https://www.cnblogs.com/vnii/p/2120798.html
Copyright © 2011-2022 走看看