• jQuery.cookie插件用法自我总结


    用的jQuery.cookie -----一个封装好了cookie的插件。(基于jQuery)

    我这只需要调用。

    $.cookie("c_name", c_value,{expires:7});

    //可通过alert($.cookie("c_name"));得到你要存储的内容,这样测试cookie是否存储;

    c_name:要创建的cookie的名字;

    c_value:值或者说要存储的内容;

    expires:7存储日期;

    $.cookie("c_name", null);//关闭cookie,可通过alert($.cookie("c_name"))的到null,就可得知已清除cookie。

     另外,每隔5分钟自动存储一次,即设置定时器

    setInterval(function(){

    $.cookie("c_name", c_value,{expires:7});

    },300000)

    $(#input).val($.cookie("c_name"));//读取cookie,并页面刷新时cookie再赋值给原对象

    再记录一下

    js获取iframe里的元素时(这是在iframe没有id或者name等的情况下):

    var  iframe = document.getElementsByTagName('iframe')[0];

    var  ifr_document = iframe.contentWindow.document;

    $(ifr_document).find('#editor');//获取iframe里id为editor的元素;

    jQuery.cookie插件源码如下:

        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();
            }
            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 {
            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]);
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };

  • 相关阅读:
    android 入门-工程属性介绍
    android 入门-android属性介绍
    android 入门-布局
    android 入门-动画与容器
    android 入门- 词汇
    android 入门-引用库项目
    android 入门-防微信拍摄视频 按钮事件处理
    WPF Adorner
    c# Quartz.net的简单封装
    WPF 触摸屏小键盘样式
  • 原文地址:https://www.cnblogs.com/web-leader/p/4219920.html
Copyright © 2020-2023  润新知