添加、获取、删除、清空全部cookie缓存数据

添加、获取、删除、清空全部cookie缓存数据

1.添加

$.cookie('keys', "11");
$.cookie('user_id', "1113", {
	path: "/"
});
$.cookie('user_name', "张三", {
	path: "/",
	expires: 30
});

2.获取

console.log($.cookie('keys'))
console.log($.cookie('user_id'))
console.log($.cookie('user_name'))

添加、获取、删除、清空全部cookie缓存数据_第1张图片

3.删除

$.removeCookie('keys'); 
$.removeCookie('user_id',{ path: '/'}); 
$.removeCookie('user_name',{path: "/",expires: -1}); 

4.清空全部

function clearCookie() {
	var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
	if (keys) {
		for (var i = keys.length; i--;) {
			$.removeCookie(keys[i]);
			$.removeCookie(keys[i],{ path: '/'});
			$.removeCookie(keys[i],{path: "/",expires: -1});
			$.removeCookie(keys[i],{path: "/",domain: document.domain,expires: -1});
			$.removeCookie(keys[i],{path: "/",domain: "mp.csdn.net",expires: -1});
		}
	}
}

 

你可能感兴趣的:(js)