我是靠谱客的博主 奋斗石头,这篇文章主要介绍添加、获取、删除、清空全部cookie缓存数据添加、获取、删除、清空全部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'))

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});
		}
	}
}

 

最后

以上就是奋斗石头最近收集整理的关于添加、获取、删除、清空全部cookie缓存数据添加、获取、删除、清空全部cookie缓存数据的全部内容,更多相关添加、获取、删除、清空全部cookie缓存数据添加、获取、删除、清空全部cookie缓存数据内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(129)

评论列表共有 0 条评论

立即
投稿
返回
顶部