• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com专业计算机教程网站
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure
您的位置:首页 > 网页设计 >心得技巧 > jquery操作cookie

jquery操作cookie

作者:佚名 字体:[增加 减小] 来源:互联网 时间:2017-08-06

本文主要包含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(); // 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; } }; function getcookie(name) { var cookie_start = document.cookie.indexOf(name); var cookie_end = document.cookie.indexOf(";", cookie_start); return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length))); } function setcookie(cookieName, cookieValue, seconds, path, domain, secure) { var expires = new Date(); expires.setTime(expires.getTime() + seconds); document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; expires=' + expires.toGMTString() : '') + (path ? '; path=' + path : '/') + (domain ? '; domain=' + domain : '') + (secure ? '; secure' : ''); }使用方法: 提供方便方法操作cookie :
$.cookie('the_cookie'); // 获得cookie $.cookie('the_cookie', 'the_value'); // 设置cookie $.cookie('the_cookie', 'the_value', { expires: 7 }); //设置带时间的cookie 7天 $.cookie('the_cookie', '', { expires: -1 }); // 删除 $.cookie('the_cookie', null); // 删除 cookie 设置cookie的名值对,有效期,路径,域,安全 $.cookie(’name’, ‘value’, {expires: 7, path: ‘/’, domain: ‘jquery.com’, secure: true});

您可能想查找下面的文章:

  • 手机网页wap用Bootstrap还是jQuery Mobile
  • jquery-multiselect在ie6里的一个bug的解决方法
  • 网页中引用jQuery的方法
  • jquery操作cookie
  • lazyLoad图片延时加载
  • nodejs extend包

相关文章

  • 2017-08-06美工自我培养的几点经验总结
  • 2018-08-23用一个实战案例,教你学会复杂界面的布局设计
  • 2018-08-23从了解用户的注意力开始,创造更优秀的用户体验
  • 2017-08-06在FireFox中导入导出Cookies与收藏夹的解决办法
  • 2018-08-23超过10亿人使用的Facebook改版了,新版的设计细节都在这儿!
  • 2018-08-23Google对话式交互规范指南(六):用户对话中的自然惯例
  • 2018-08-23这5种成熟的导航设计模式,可以为用户体验加分
  • 2018-08-23腾讯高级交互设计师:什么是优秀的设计思维与方法?
  • 2018-08-23腾讯出品!从零开始制作设计规范的实用指南
  • 2018-08-23世界上最受欢迎的色彩出炉了,她的名字叫马尔斯绿!

文章分类

  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure

最近更新的内容

    • 实用干货!如何进行一场高质量的UI设计评审?
    • 对背景图定位中background-position属性的自我理解
    • 原型工具哪家强!我从10个角度对比了素描和Axure的优缺点
    • 想做好产品功能,不妨试试这个「亲亲原则」
    • 腾讯ISUX :2018年的品牌体验趋势
    • 优设首发!iPhone X 官方人机交互指南中文版
    • 10个Sketch搭配Zeplin的使用技巧,让你和程序员愉快玩耍!
    • 人工智能对设计有哪些影响?来看这篇超全面的总结!
    • 这些小小的改变,能够让UI动效更上一层楼
    • 上亿人使用的手机淘宝卡券包,设计师是这么做改版的!

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有