当前位置:网站首页>cookie增删改查方法
cookie增删改查方法
2022-07-26 23:18:00 【kilito_01】
/**
* 设置cookie
* @param {
*cookie名称} name
* @param {
*cookie值} value
*/
function setCookie(name, value, old_expires) {
var argv = arguments;
var argc = arguments.length;
var expires = (argc > 2) ? argv[2] : null;
if (expires != null) {
var LargeExpDate = new Date();
LargeExpDate.setTime(LargeExpDate.getTime() + (expires * 1000 * 3600 * 24));
}
document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : (";path=/;expires=" + LargeExpDate.toGMTString()));
}
/**
* 读取cookie
* @param {
*cookie名称} Name
*/
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) {
var offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
var end = document.cookie.indexOf(";", offset)
if (end == -1) end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
else return ""
}
}
/**
* 删除cookie
* @param {
*cookie名称} name
*/
function deleteCookie(name) {
var expdate = new Date();
expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
setCookie(name, "", expdate);
}
function clearCookie(){
var keys=document.cookie.match(/[^ =;]+(?=\=)/g);
if (keys) {
for (var i = keys.length; i--;)
document.cookie=keys[i]+'=0;expires=' + new Date( 0).toUTCString()
}
}
export {
setCookie, getCookie, deleteCookie,clearCookie }
边栏推荐
- C language student information management system can access text files based on arrays
- Writing a pacesetter frequently -- yunxiaojing
- How to judge whether a number is odd or even?
- Hcip day 1
- 线程和进程
- 使用注解方式实现 Redis 分布式锁
- 静态路由基本配置 实现全网可达
- 【自此文之后,学习链表一片坦途】
- [draw rectangular coordinate system in C language]
- Witness that the "decoding 2022 strong star of China's network security" is about to set sail
猜你喜欢
![[use SQLite3 library to realize student information management system in Visual Studio 2019]](/img/49/5d6c47654e446ab96099a821a16369.png)
[use SQLite3 library to realize student information management system in Visual Studio 2019]

NAT网络地址转化实验

砺夏行动|源启数字化:既有模式,还是开源创新?

OSPF basic experimental configuration

多线程的具体使用
![[after this article, learning the linked list is a smooth way]](/img/e7/cbdfecd1d98f91ecfeeb620b265f89.png)
[after this article, learning the linked list is a smooth way]

JUC concurrent programming

Handsomeforum Learning Forum

The latest multi-threaded & highly concurrent learning materials, interview confidence

Find a specific number in an ordered array
随机推荐
【封神演绎、十五分钟让你彻底学会栈的使用!!!】
Hcip first day
How does the whole network display IP ownership?
Static routing experiment configuration
After ten years of testing, I want to say to my friends who are still confused: one thing is to do a good job in personal planning
在腾讯测试岗干了5年,7月无情被辞,想给还在划水的兄弟提个醒.....
On the first day of staying in the blog [for 80000]!
[Fibonacci sequence and spiral are based on C language]
Hcip day 3 Wan topology experiment
NAT网络地址转换协议-拓扑实验
What is the principle of synchronized lock escalation in multithreading?
HCIP-第三天-广域网拓扑实验
Today, let's talk about escape characters [cute new version]
C language - characters and strings, arithmetic operators, type conversions
多线程的具体使用
Handsomeforum Learning Forum
Encyclopedia of websites commonly used by people who know current affairs
【洋哥带你玩转线性表(三)——双向链表】
[C language programming] branch structure
LeetCode->二分查找打卡(三)