zoukankan      html  css  js  c++  java
  • Js 添加cookie,写入cookie到主域

    if (getCookie("content") != null && getCookie("content") != "") //判断cookie不为空
    不能简单使用上面这种
    正确方法是:判断是否存在名为username3的cookie,使用document.cookie.indexOf(“username3=”)来判断,如果返回值是-1,表示不存在。
    setCookie("content", cotent, 1);//设置cookie
    //设置cookie
    function setCookie(name, value, day) {
        var date = new Date();
        date.setDate(date.getDate() + day);
        //domain=.cnblogs.com;写入cookie到主域 子域名都可用    path=/表示本站全部路径都可使用
        document.cookie = name + '=' + value + ';expires=' + date + ';domain=.cnblogs.com;path=/';
    };
    //获取cookie
    function getCookie(name) {
        var reg = RegExp(name + '=([^;]+)');
        var arr = document.cookie.match(reg);
        if (arr) {
            return arr[1];
        } else {
            return '';
        }
    };
    //删除cookie
    function delCookie(name) {
        setCookie(name, null, -1);
    };
  • 相关阅读:
    c# 读取数据库得到dateset
    c# 读数据库二进制流到图片
    c# 读取数据库得到字符串
    c#打开颜色对话框
    WinForm-GridView
    arcengine 常用方法
    arcgis engine 调用arcgis server服务
    ae
    ae保存图层
    ae 打开地图文档
  • 原文地址:https://www.cnblogs.com/netlock/p/13433537.html
Copyright © 2011-2022 走看看