zoukankan      html  css  js  c++  java
  • 关于cookie 保存操作动作的时间

    //设置Cookies
    var Cookies = {};

    存入Cookies
    Cookies.set = function (name, value) {
        var argv = arguments;
        var argc = arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : '/';
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape(value) +
          ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
          ((path == null) ? "" : ("; path=" + path)) +
          ((domain == null) ? "" : ("; domain=" + domain)) +
          ((secure == true) ? "; secure" : "");
    };

    取出Cookies
    Cookies.get = function (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        var j = 0;
        while (i < clen) {
            j = i + alen;
            if (document.cookie.substring(i, j) == arg)
                return Cookies.getCookieVal(j);
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0)
                break;
        }
        return null;
    }

    前台页面调用

    var exdate=new Date();
            exdate.setDate(exdate.getDate()+365);  //设置保存时间
            Cookies.set("receiptform", $("#OkIsGenType input[name=OkIsGen]:checked").val(), exdate);

    //页面加载取出cookies 
    设置值

    if (Cookies.get("receiptform") != undefined) {
                $("#OkIsGenType input[name=OkIsGen][value=" + Cookies.get("receiptform") + "]").prop("checked", true);
            }

  • 相关阅读:
    c++笔记
    python笔记
    《c++不在难学--随老鸟快速通关》
    hexo
    hexo搭建
    《趣学算法》,陈小玉
    从机器学习谈起
    成不了AI高手?因为你根本不懂数据!听听这位老教授多年心血练就的最实用统计学
    PyTorch还是TensorFlow?这有一份新手指南
    win10下机器学习TensorFlow搭建
  • 原文地址:https://www.cnblogs.com/Davi123/p/7324992.html
Copyright © 2011-2022 走看看