最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery插件如何使用 jQuery操作Cookie插件使用介紹

 更新時間:2012年12月15日 16:31:52   作者:  
本文將介紹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 = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
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
}
// NOTE Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
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;
}
};

使用方法
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
設置一個名稱為blog,值為css9.net的cookie:
$.cookie("blog", "css9.net");
設置一個名稱為blog,值為css9.net的cookie,同時設置過期時間(expires屬性)為7天:
$.cookie("blog", "css9.net", { expires: 7 });
設置一個名稱為blog,值為css9.net的cookie,設置過期時間(expires屬性)為7天,同時設置cookie的path屬性為”/admin”
$.cookie("blog", "css9.net", { path: '/admin', expires: 7 });
讀取Cookie:
讀取名稱為blog的cookie值:
alert( $.cookie("blog") );
刪除cookie:
$.cookie("example", null);

相關文章

最新評論

赣榆县| 武功县| 三门峡市| 筠连县| 吉安县| 静海县| 惠东县| 九龙县| 通化县| 鄄城县| 清水县| 乌兰浩特市| 玉龙| 邹平县| 安顺市| 海晏县| 鸡泽县| 尚志市| 武隆县| 噶尔县| 哈密市| 宜黄县| 福安市| 无棣县| 莒南县| 明光市| 溧阳市| 准格尔旗| 南昌县| 三门县| 南川市| 临澧县| 防城港市| 田阳县| 宜黄县| 包头市| 兴海县| 桃源县| 芮城县| 六盘水市| 怀集县|