(摘) Javascript中加载jQuery及其它脚本、CSS等

声明:内容源自网络,版权归原作者所有。若有侵权请在网页聊天中联系我
//引入css
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = baseUrl+'/css/style.css';
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);

//引入js
//var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = 'http://libs.baidu.com/jquery/1.8.3/jquery.min.js';
script.type = 'text/javascript';
head.appendChild(script);

//载入jquery后,再载入其它js
//若不等待,直接载入其它js,可能存在jquery还未载入,其它二次开发的js就不能正常使用。
waitQuery = window.setInterval(function(){ 
    if(typeof jQuery != 'undefined'){
        window.clearInterval(waitQuery);
        $.getScript(baseUrl+'/js/juqery-translucent-min.js',function(){
            //建立窗口            
            $("body").translucent({
                target:"serviceWin",
                width:w,
                textHtml:"<div>这是一个新建的弹窗!</div>",
                titleText:"弹窗标题内容"
            });

            var div = document.getElementsByClassName("translucent-title")[0];
            console.log(div.innerHTML);

        });  
    }  
 },100);

//js中动态加载div
var div = document.createElement("div");
div.innerHTML = "微客服网页版开发中...";
div.setAttribute("id","fl");
div.style.width=w+"px";
div.style.height=h+"px";
div.style.top="-1000px";
div.style.background="#eee";
div.style.position="fixed";
document.body.appendChild(div);