Use jquery to dynamically load Js and Css files, and jquerycss
If you have many associated CSS files to be loaded together, or want to dynamically load different CSS files, the following methods must be helpful to you.
Jquery dynamic loading Js and Css extension methods
$.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 + ">"); } } });
Usage:
$.include('http://www.bkjia.com/include/dedeajax.js'); $.include('http://www.bkjia.com/templets/skins/style/android.css');
Or:
$.includePath='www.jb51.net/html/'; $.include([dedeajax.js','android.css']);
The above is all the content of this article, hoping to help you learn.