js动态加载js,css函数
来源:网络 作者:佚名 点击:
次时间:2017-08-07 22:13
[摘要] js动态加载js,css函数,项目中使用到的,拿出来分享一下给大家,希望对大家学习有所帮助。
-
-
- $.extend({
- include: function(file)
- {
- var files = typeof file == "string" ? [file] : file;
-
- for (var i = 0; i < files.length; i++)
- {
- var name = files[i].replace(/^\s|\s$/g, "");
- var att = name.split('.');
- var ext = att[att.length - 1].toLowerCase();
- var isCSS = ext == "css";
- var tag = isCSS ? "link" : "script";
- var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language='javascript' type='text/javascript' ";
- var link = (isCSS ? "href" : "src") + "='" + SITEURL+'/' + name + "'";
- if ($(tag + "[" + link + "]").length == 0) $('body').append("<" + tag + attr + link + "></" + tag + ">");
- }
- }
- });
实例如下:
$.include(['http://www.bcty365.com/script/a.js','/css/css.css']);
|
------分隔线----------------------------