*/
function getcookie(name, dc){
var cname = name + "=";
if (dc.length > 0){
var begin = dc.indexof(cname);
if (begin != -1){
begin += cname.length;
end = dc.indexof(",", begin);
if (end == -1){
end = dc.length;
}
return dc.substring(begin, end);
}
}
return null;
}
//jquery取值比较简单,因为他有个自带函数
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
}
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;
}
};
//使用方法
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: '3ppt.com', secure: true });
jquery cookie 存取json jquery获取cookie的值
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章