网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 如何现实动态加载JS代码?
内容
    如何现实动态加载JS代码,调用方法:
    FloadJS(url,function(){alert("加载成功!")},function(){alert("加载失败!");});
    具体代码如下:
    var FBrowser=new Object();
    FBrowser.isIE=((navigator.userAgent.indexOf('MSIE')==-1)?false:true);
    FBrowser.isIE7=((FBrowser.isIE&&window.XMLHttpRequest)?true:false);
    FBrowser.isIE6=((FBrowser.isIE&&!window.XMLHttpRequest&&window.ActiveXObject)?true:false);
    FBrowser.isFirefox=((navigator.userAgent.indexOf('Firefox')==-1)?false:true);
    FBrowser.isOpera=((navigator.userAgent.indexOf('Opera')==-1)?false:true);
    function FloadJS(url,sucfn,failfn){
    var h=document.getElementsByTagName('HEAD').item(0);
    var js=document.createElement("script");
    js.type="text/javascript";
    js.onerror=function(){
    if('function'==typeof(failfn))
    failfn();
    js=null;
    }
    if(FBrowser.isIE){
    js.onreadystatechange=function(){
    if(this.readyState.toLowerCase()!="complete"&&this.readyState.toLowerCase()!="loaded") return;
    if(this.$funExeced!=true&&'function'==typeof(sucfn)){
    this.$funExeced=true;
    h.removeChild( js );
    sucfn();
    }
    js=null;
    }
    }
    /*else if(FBrowser.isOpera){
    // if('function'==typeof(sucfn)) sucfn();
    }*/
    else{
    js.onload=function(){
    if('function'==typeof(sucfn)) {sucfn();h.removeChild( js );}
    js=null;
    }
    }
    js.src=url;
    h.appendChild(js);
    //if(FBrowser.isOpera && 'function'==typeof(sucfn)) {sucfn();h.removeChild( js );}
    }/* |xGv00|bc90a4beab01b556cf45cf4090728b7f */
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/20 20:21:22