Js实现css的@import
JS代码
(function () {
//获取script
var obj = document.getElementsByTagName("script");
//获取当前script的路径
var src = obj[obj.length - 1].src;
src = src.substring(0, src.lastIndexOf("/") + 1);
//设置要引入的js文件名(这些文件最好和本JS在一个目录下)
var arr = "jquery-1.4.1.js,MyJQuery.js".split(",");
//循环引入
for (var i = 0; i < arr.length; i++) {
document.write("<script type='text/javascript' src='" + src + arr[i] + "'><\/script>");
}
})()
//获取script
var obj = document.getElementsByTagName("script");
//获取当前script的路径
var src = obj[obj.length - 1].src;
src = src.substring(0, src.lastIndexOf("/") + 1);
//设置要引入的js文件名(这些文件最好和本JS在一个目录下)
var arr = "jquery-1.4.1.js,MyJQuery.js".split(",");
//循环引入
for (var i = 0; i < arr.length; i++) {
document.write("<script type='text/javascript' src='" + src + arr[i] + "'><\/script>");
}
})()
JS代码2
(function(){
var obj = document.getElementsByTagName("script");
var str = obj[obj.length-1].innerHTML.replace(/\./g, "/");
var arr = str.match(/[^\s+]+(?=;)/g);
for(var i = 0; i < arr.length; i++){
document.write("<script type='text/javascript' src='"+arr[i]+"'><\/script>");
}
})()
var obj = document.getElementsByTagName("script");
var str = obj[obj.length-1].innerHTML.replace(/\./g, "/");
var arr = str.match(/[^\s+]+(?=;)/g);
for(var i = 0; i < arr.length; i++){
document.write("<script type='text/javascript' src='"+arr[i]+"'><\/script>");
}
})()
页面引用
//js代码1
<script type="text/javascript" src="js/import.js"></script>
//js代码2
<script type="text/javascript" src="js/import2.js">
@import jquery-1.4.4.min.js;
@import jquery.validate.js;
@import ../js2/MyJQuery.js;
</script>
<script type="text/javascript" src="js/import.js"></script>
//js代码2
<script type="text/javascript" src="js/import2.js">
@import jquery-1.4.4.min.js;
@import jquery.validate.js;
@import ../js2/MyJQuery.js;
</script>