加载js


commonsCSS=[

]
commonsJS = [
    "js/jquery-3.3.1.min.js",
    "js/bootstrap.min.js"
];



//index,是在head里加载的,after是等到加载完毕后 在body最下面加载
var config = {
    index: {
        before: [
                "js/swiper-4.3.3.min.js",
                "js/swiper.animate1.0.3.min.js"
        ],
        after: [
                    "js/vue.min.js"
        ],css:[
        
        ]
    },
    editpage: {
        before:  [
                    "js/jquery-3.3.1.min.js",
                    "js/bootstrap.min.js"
                ],
        after:  [   
                    "js/bootstrap.min.js", 
                    "plug/page/listen/pageControlListen.js"
                ]
    },

}




































































/**
 * 置顶变量
 */

var jsUrl = new Array();

var bodyDom;

/**
 * 初始化 加载js
 */

function pageName() {
    var a = location.href;
    var b = a.split("/");
    var c = b.slice(b.length - 1, b.length).toString(String).split(".");
    return c.slice(0, 1);
}

function createScript(src) {
    var scr = document.createElement("script");
    scr.setAttribute("type", "text/javascript");
    scr.setAttribute("src", src);

    return scr;

}

window.onload = function() {
    bodyDom = document.body;
    for(var u = 0; u < jsUrl.length; u++) {
        bodyDom.appendChild(createScript(jsUrl[u]));
    }

}
function importCss(url)
{
    document.write('');
}
function importJs(url) {
    document.write('');
}

function commonImportJs(url) {
    document.write('');
}

function importAfterLoad(url) {
    jsUrl.push(url);

}

function loadJs(pageName) {
    if(config[pageName] != null || config[pageName] != undefined) {

        var page = config[pageName];
        //加载公用的

        for(var i = 0; i < commons.length; i++) {
            importJs(commons[i]);
        }

        //加载顶层的
        var topJs = page.before;
        for(var i = 0; i < topJs.length; i++) {
            importJs(topJs[i]);
        }

        var bttomJs = page.after;
        
        for(var i = 0; i < bttomJs.length; i++) {
            importAfterLoad(bttomJs[i]);
        }

    } else {
        console.error("可能是你没有配置该网页的js")
    }
}

loadJs(pageName());


你可能感兴趣的:(加载js)