zoukankan      html  css  js  c++  java
  • jquery.cookie

    $.cookie('the_cookie'); //读取Cookie值
    $.cookie(’the_cookie’, ‘the_value’); //设置cookie的值
    $.cookie(’the_cookie’, ‘the_value’, {expires: 7, path: ‘/’, domain: ‘jquery.com’, secure: true});//新建一个cookie 包括有效期 路径 域名等
    $.cookie(’the_cookie’, ‘the_value’); //新建cookie
    $.cookie(’the_cookie’, null); //删除一个cookie
     
    JQuery.cookie源代码
    Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
    jQuery.cookie = function(name, value, options) {
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            var path = options.path ? '; path=' + options.path : '';
            var domain = options.domain ? '; domain=' + options.domain : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };

    作者:石世特
    出处:http://www.cnblogs.com/TivonStone/
    希望本文对你有所帮助,想转随便转,心情好的话给我的文章留个链接.o(. .)o

  • 相关阅读:
    Linux:grep 命令
    Linux:sort
    Java中路径相关的获取方式
    Spring boot 配置 Tomcat 临时文件缓存目录
    zabbix :web 界面显示的监控项值为0或者空
    Maven:禁止编码指定类型的资源文件
    Maven:element '******' cannot have character [children]
    MySQL:数据库名或者数据表名包含-
    Linux:sed
    Lucene 6.0下使用IK分词器
  • 原文地址:https://www.cnblogs.com/TivonStone/p/2549079.html
Copyright © 2011-2022 走看看