美文网首页
JS动态加载js/css文件

JS动态加载js/css文件

作者: jesn | 来源:发表于2017-01-18 16:46 被阅读134次

     var dynamicLoading = {

    css: function (path) {

    if (!path || path.length === 0) {

    throw new Error('argument "path" is required !');

    }

    var head = document.getElementsByTagName('head')[0];

    var link = document.createElement('link');

    link.href = path;

    link.rel = 'stylesheet';

    link.type = 'text/css';

    head.appendChild(link);

    },

    js: function (path) {

    if (!path || path.length === 0) {

    throw new Error('argument "path" is required !');

    }

    var head = document.getElementsByTagName('head')[0];

    var script = document.createElement('script');

    script.src = path;

    script.type = 'text/javascript';

    head.appendChild(script);

    }

    }

    //动态加载 JS 文件

    dynamicLoading.css("skin/css/2017NewYear/xinnian.css");

    相关文章

      网友评论

          本文标题:JS动态加载js/css文件

          本文链接:https://www.haomeiwen.com/subject/bohbbttx.html