533   CSS JS

有时候需要通过js判断不同客户端,不同浏览器,不同版本,加载不同js和css
加载方法例子

var dynamicLoading = {
    css: function(path){
	var head = document.getElementsByTagName('head')[0];
        var link = document.createElement('link');
        link.href = path;
        link.rel = 'stylesheet';
        link.type = 'text/css';
        head.appendChild(link);
    },
    js: function(path){
	var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');
        script.src = path;
        script.type = 'text/javascript';
        head.appendChild(script);
    }
}

使用JQ方法

$("<link>").attr({ 
rel: "stylesheet",
type: "text/css",
href: "site.css"}
).appendTo("head");


$("<script>").attr({ 
type: "text/javascript",
href: "site.js"}
).appendTo("head");




Leave a Reply

Your email address will not be published. Required fields are marked *