zoukankan      html  css  js  c++  java
  • js cookie常用操作

    /**
     * [setCookie 设置cookie]
     * @param {[type]} name  cookie名称
     * @param {[type]} value cookie值
     * @param {[type]} time  时间(例如20s或1h)
     */
    function setCookie(name, value, time) {
    var strsec = getsec(time); var exp = new Date(); exp.setTime(exp.getTime() + strsec * 1); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); } /** * [getsec 获取毫秒数] * @param {[type]} str [description] * @return {[type]} [description] */ function getsec(str) { var str1 = str.substring(1, str.length) * 1; var str2 = str.substring(0, 1); if (str2 == "s") { return str1 * 1000; } else if (str2 == "h") { return str1 * 60 * 60 * 1000; } else if (str2 == "d") { return str1 * 24 * 60 * 60 * 1000; } } /** * [getCookie 读取cookies ] * @param {[type]} name [description] * @return {[type]} [description] */ function getCookie(name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return null; } /** * [delCookie 删除cookies ] * @param {[type]} name [description] * @return {[type]} [description] */ function delCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 60 * 60 * 1000); var cval = getCookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + ";path=/"; }
  • 相关阅读:
    一个统计代码行数的简单方法
    关于string的对象引用
    mysql连接的一些问题。
    linux环境初始化 用户问题
    php null o false ''
    php支付宝在线支付接口开发教程【转】
    模拟支付宝服务窗环境
    ctags
    校验全球电话号码 正确性 库 正则表达式
    php短路与 短路或
  • 原文地址:https://www.cnblogs.com/mankii/p/10137983.html
Copyright © 2011-2022 走看看