js调用公共部分js,css

/**
 * 引用JS和CSS头文件
 */
var rootPath = getRootPath(); //项目路径
/**
 * 动态加载CSS和JS文件
 */
var dynamicLoading = {
    meta : function(){
        document.write('');
    },
    css: function(path){
        if(!path || path.length === 0){
            throw new Error('argument "path" is required!');
        }
        document.write('');
    },
    js: function(path, charset){
        if(!path || path.length === 0){
            throw new Error('argument "path" is required!');
        }
        document.write('');
    }
};
/**
 * 取得项目路径
 * @author wul
 */
function getRootPath() {
    //取得当前URL
    var path = window.document.location.href;
    //取得主机地址后的目录
    var pathName = window.document.location.pathname;
    var post = path.indexOf(pathName);
    //取得主机地址
    var hostPath = path.substring(0, post);
    //取得项目名
    var name = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
    return hostPath + name + "/";
}
//动态生成meta
dynamicLoading.meta();
//动态加载项目 JS文件
dynamicLoading.js(rootPath + "js/jquery.min.js", "utf-8");
dynamicLoading.js("/js/ceshi.js", "utf-8");

//动态加载项目 CSS文件
dynamicLoading.css(rootPath + "css/index.css");
点赞

发表评论