zoukankan      html  css  js  c++  java
  • Cookie

        $(".theme-colors > li > span").hover(function(e) {
            var t = $(this),
            n = $("body");
            n.attr("class", "").addClass("theme-" + t.attr("class"));
        },
        function() {
            var e = $(this),
            t = $("body");
            t.attr("data-theme") !== undefined ? t.attr("class", "").addClass(t.attr("data-theme")) : t.attr("class", "")
        }).click(function() {
            var e = $(this);
            $("body").addClass("theme-" + e.attr("class")).attr("data-theme", "theme-" + e.attr("class"));
            addCookie('text_class', e.attr("class"), 86400 * 30);
        });
    /cookie 开始/
    var addCookie = function(objName, objValue, objHours) {
            var str = objName + "=" + escape(objValue);
            if (objHours > 0) {
                var date = new Date();
                var ms = objHours * 3600 * 1000 * 24;
                date.setTime(date.getTime() + ms);
                str += ";path=/; expires=" + date.toGMTString();
            }
            document.cookie = str;
        },
        getCookie = function(objName) {
            var arrStr = document.cookie.split("; ");
            for (var i = 0; i < arrStr.length; i++) {
                var temp = arrStr[i].split("=");
                if (temp[0] == objName) return unescape(temp[1]);
            }
        },
        class_ = getCookie('text_class');
        class_ && $("body").addClass("theme-" + class_).attr("data-theme", "theme-" + class_);
    
    /cookie 结束/
    
    
    
    原本
    可以更换样式的名称 
    或者是一个样式一个css文件 ,到时候更换 css文件即可。 
    cookie 操作类 100%可用
    
    /////------------------------js cookie操作类-------------------begin   [edit by ygd]
    function addCookie(objName, objValue, objHours) {//添加cookie
        var str = objName + "=" + escape(objValue);
        if (objHours > 0) {//为0时不设定过期时间,浏览器关闭时cookie自动消失
            var date = new Date();
            var ms = objHours * 3600 * 1000 * 24;
            date.setTime(date.getTime() + ms);
            str += "; expires=" + date.toGMTString();
        }
        document.cookie = str;
    }
    function getCookie(objName) {//获取指定名称的cookie的值
        var arrStr = document.cookie.split("; ");
        for (var i = 0; i < arrStr.length; i++) {
            var temp = arrStr[i].split("=");
            if (temp[0] == objName) return unescape(temp[1]);
        }
    }
    /////------------------------js cookie操作类-------------------end
    高否?富否?帅否? 否? 滚去学习!
  • 相关阅读:
    @Value不能给静态变量直接赋值问题
    jmeter测试http请求
    SqlServer单步调试
    mysql锁住 Lock wait timeout exceeded; try restarting transaction
    django在model中添加字段报错
    django admin下拉列表不显示值,显示为object的处理
    (原创推荐文章)kerberos服务器端与客户端
    kafka安装与测试
    Linux shell判断文件和文件夹是否存在
    df -h 卡死 如何解决
  • 原文地址:https://www.cnblogs.com/baixc/p/3881453.html
Copyright © 2011-2022 走看看