使用jquery动态加载js文件的方法
作者:bea
方法很简单,这里就不多废话了,直接奉上代码: 代码如下: $.extend({ includePath: '', 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
方法很简单,这里就不多废话了,直接奉上代码:
代码如下:
$.extend({
includePath: '',
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") + "='" + $.includePath + name + "'";
if ($(tag + "[" + link + "]").length == 0) $("body").append("<" + tag + attr + link + "></" + tag + ">");
}
}
});
//使用方法 $.includePath = '../js/Exam'; $.include(['/AddQuestion.js']);
小伙伴们如果有什么疑问就在下面留言吧,大家共同进步。
有用 | 无用
代码如下:
$.extend({
includePath: '',
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") + "='" + $.includePath + name + "'";
if ($(tag + "[" + link + "]").length == 0) $("body").append("<" + tag + attr + link + "></" + tag + ">");
}
}
});
//使用方法 $.includePath = '../js/Exam'; $.include(['/AddQuestion.js']);
小伙伴们如果有什么疑问就在下面留言吧,大家共同进步。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- 2014 年最热门的21款JavaScript框架推荐
- jQuery中after()方法用法实例
- jQuery中prepend()方法用法实例
- jQuery中append()方法用法实例
- 使用mini-define实现前端代码的模块化管理
- jQuery中html()方法用法实例
- jQuery中val()方法用法实例
- 24款热门实用的jQuery插件推荐
- js获取当前时间显示在页面上并每秒刷新
- Javascript 多物体运动的实现
- Javascript 运动中Offset的bug解决方案
- jQuery中height()方法用法实例
- jQuery中width()方法用法实例
- jQuery中animate()方法用法实例
- jQuery中fadeOut()方法用法实例
- 创建js对象和js类的方法汇总
- javascript使用prototype完成单继承
- jQuery中slideUp()方法用法分析
- node.js开机自启动脚本文件