联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

如何使用jquery动态加载js,css文件实现代码 - Web前端

作者:98wpeu发布时间:2026-06-22分类:网页前端技术浏览:4


导读:使用JQuery动态加载JS,CSS文件复制代码代码如下:$.extend({includePath:'',include:function(file){varf...
使用JQuery动态加载JS,CSS文件
复制代码 代码如下:
$.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) document.write("<" + tag + attr + link + "></" + tag + ">");
}
}
});

//使用方法
$.includePath = 'http://hi.bAIdu.com/Javascript/';
$.include(['json2.js', 'jQuery.tree.js', 'jquery.tree.css']);

标签:如何使用加载代码文件动态Web


网页前端技术排行
最近发表
网站分类
标签列表