• Javascript Cookie 操作包 | Cookie 操作函数


    这个美味地“小甜饼”是哪个网站都缺少不了的,“让我们讨一下 Cookie 小怪兽的欢心,做一块儿小甜饼吧~~”:来看源码:

    /**
     * jscript.storage package
     * This package contains functions for doing client-side storage, including
     * cookie functions.
     */
    if (typeof jscript == 'undefined') {
      jscript = function() { }
    }
    jscript.storage = function() { }
    
    /**
     * Sets a cookie.
     *(设置 Cookie)
     * @param inName   The name of the cookie to set.
     * @param inValue  The value of the cookie.
     * @param inExpiry A Date object representing the expiration date of the
     *                 cookie.
     */
    jscript.storage.setCookie = function(inName, inValue, inExpiry) {
    
      if (typeof inExpiry == "Date") {
        inExpiry = inExpiry.toGMTString();
      }
      document.cookie = inName + "=" + escape(inValue) + "; expires=" + inExpiry;
    
    } // End setCookie().
    
    /**
     * Gets thbe value of a specified cookie.  Returns null if cookie isn't found.
     *(得到指定 Cookie 的值)
     * @param inName The name of the cookie to get the value of.
     */
    jscript.storage.getCookie = function(inName) {
    
      var docCookies = document.cookie;
      var cIndex = docCookies.indexOf(inName + "=");
      if (cIndex == -1) {
        return null;
      }
      cIndex = docCookies.indexOf("=", cIndex) + 1;
      var endStr = docCookies.indexOf(";", cIndex);
      if (endStr == -1) {
        endStr = docCookies.length;
      }
      return unescape(docCookies.substring(cIndex, endStr));
    
    } // End getCookie().
    
    /**
     * Deletes a cookie.(删除 Cookie)
     */
    jscript.storage.deleteCookie = function(inName) {
    
      if (this.getCookie(inName)) {
        this.setCookie(inName, null, "Thu, 01-Jan-1970 00:00:01 GMT");
      }
    
    } // End deleteCookie().

    点击试一下:



  • 相关阅读:
    multiview
    RadioButton
    信息存储与管理读书笔记1
    个人Wordpress站点设置Windows Live writer
    test
    test
    AS类库推荐
    JAVA坏境变量中的JAVA_HOME path classpath 的设置与作用
    actionscript3 中关于sprite的mask问题
    RED5遍历客户端并生成在线列表[转]
  • 原文地址:https://www.cnblogs.com/catprayer/p/1861929.html
Copyright © 2020-2023  润新知