web css实现整站样式切换

//取元素 用两个$是为了不与jquery冲突
function $$(s) {
    return document.getElementById(s);
}
function setblue() {
    //先写cookie
    //writeCookie("ISCSSSTYLE", "css/CRM_blue.css", 365, true);
    //设置新的css文件
    $$("maincss").href = "css/CRM_blue.css";
    //取主框架页,并重新设置css文件
    //var childobj = window.parent.document.getElementById("ManagerMain").contentWindow;
    //childobj.document.getElementById("maincss").href = "css/CRM_blue.css";
}
function setgreen() {
    //先写cookie
    //writeCookie("ISCSSSTYLE", "css/CRM.css", 365, true);
    //设置新的css文件
    $$('maincss').href = "css/CRM.css";
    //取主框架页,并重新设置css文件
    //var childobj = window.parent.document.getElementById("ManagerMain").contentWindow;
    //childobj.document.getElementById("maincss").href = "css/CRM.css";
}
function setgray() {
    //先写cookie
    //writeCookie("ISCSSSTYLE", "css/CRM_gray.css", 365, true);
    //设置新的css文件
    $$('maincss').href = "css/CRM_gray.css";
    //取主框架页,并重新设置css文件
    //var childobj = window.parent.document.getElementById("ManagerMain").contentWindow;
    //childobj.document.getElementById("maincss").href = "css/CRM_gray.css";
}


function setActiveStyleSheet(title) {
    //    var i, a, main;  
    //    for(i=0; (a = document.getElementsByTagName("link")[i]); i++)  
    //    {  
    //        if(a.getAttribute("rel").indexOf("style")!= -1 && a.getAttribute("title"))  
    //        {  
    //            a.disabled = true;  
    //            if(a.getAttribute("title") == title)  
    //            a.disabled = false;  
    //        }
    //    }
    //$$("maincss").attr("href", "css/CRM_blue.css");
    //$$('maincss').href = "css/CRM_blue.css";
    //设置css的文件
    $$('maincss').href = title;
}
function getActiveStyleSheet() {
    //    var i, a;  
    //    for(i=0; (a = document.getElementsByTagName("link")[i]); i++)  
    //    {  
    //        if(a.getAttribute("rel").indexOf("style")!= -1 &&  
    //         a.getAttribute("title") && !a.disabled)  
    //            return a.getAttribute("title");  
    //    }
    //    return null;
    var cssfile = $$('maincss').href;
    //alert(cssfile);
    return cssfile;
}
function getPreferredStyleSheet() {
    //    var i, a;  
    //    for(i=0; (a = document.getElementsByTagName("link")[i]); i++)  
    //    {  
    //        if(a.getAttribute("rel").indexOf("style") != -1  
    //            && a.getAttribute("rel").indexOf("alt") == -1  
    //            && a.getAttribute("title"))  
    //            return a.getAttribute("title");  
    //    }
    //    return null;
    var cssfile = $$('maincss').href;
    //alert(cssfile);
    return cssfile;
}
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else
        expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";


}
function writeCookie(name, value, hours, escp) {
    var expire = "";
    if (hours != null) {
        expire = new Date((new Date()).getTime() + hours * 3600000);
        expire = "; expires=" + expire.toGMTString();
    }
    if (escp == "True") {
        document.cookie = name + "=" + value + expire;
    } else {
        document.cookie = name + "=" + escape(value) + expire;
    }
}


function readCookie(name) {
    var nameEQ = name + "=";


    var ca = document.cookie.split(';');


    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];


        while (c.charAt(0) == ' ')
            c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0)
            return c.substring(nameEQ.length, c.length);
    }
    return null;
}
$(document).ready(function() {


    //var title = readCookie("ISCSSSTYLE");
    //var title = "css/CRM_blue.css";


    //if (title != null && title != "undefined") {
    //    setActiveStyleSheet(title);
    //}
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值