星空网 > 软件开发 > Java

jQuery操作cookie代码实例

jQuery操作cookie代码实例:
cookie是非常好用的,设置网站中不可获取的,例如可以记住用户的一些访问信息,以便下一次访问的时候直接使用就可以了,所以对于cookie的操作是很重要的意向技能,下面是一段jquery操作cookie的插件,希望能够对需要的朋友带来一定的帮助。
插件代码如下:

jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined'){  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; }};

使用说明:
1.设置指定cookie的值:
$.cookie('name', ‘value');
2.创建一个新的cookie包括有效期 路径 域名等:
$.cookie('name', ‘value', {expires: 7, path: ‘/', domain: ‘jquery.com', secure: true});
3.创建一个普通cookie:
$.cookie('name', ‘value');
4.删除一个cookie:
$.cookie('name', null);
5.获取一个cookie的值:
$.cookie('name')。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=10642

更多内容可以参阅:http://www.softwhy.com/jquery/




原标题:jQuery操作cookie代码实例

关键词:jquery

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

手机寄国际快递:https://www.goluckyvip.com/tag/101135.html
ems国际快运价格:https://www.goluckyvip.com/tag/101136.html
ems快运国际价格:https://www.goluckyvip.com/tag/101137.html
jc国际快递:https://www.goluckyvip.com/tag/101138.html
国际物流托运报价:https://www.goluckyvip.com/tag/101139.html
蚍蜉撼树:https://www.goluckyvip.com/tag/10114.html
云南抚仙湖旅游攻略更佳行程安排,景点攻略大全:https://www.vstour.cn/a/408242.html
珠海附近过年旅游景点 珠海附近过年旅游景点免费:https://www.vstour.cn/a/408243.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流