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

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

 更新時間:2012年12月15日 16:31:52   作者:  
本文將介紹jQuery如何操作Cookie插件,需要了解的朋友可以參考下
代碼:
復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評論

洛浦县| 扎赉特旗| 家居| 西充县| 营口市| 贵德县| 江源县| 杂多县| 台安县| 洛南县| 扬中市| 磴口县| 博客| 永川市| 株洲市| 太和县| 宁德市| 涿州市| 碌曲县| 博兴县| 航空| 卢氏县| 东乌珠穆沁旗| 赤水市| 永新县| 定安县| 翼城县| 获嘉县| 玛多县| 隆林| 淮安市| 米易县| 平武县| 略阳县| 新民市| 阿拉善左旗| 博爱县| 滨海县| 溧水县| 磐石市| 恭城|