js对cookie的操作:读、写、删
2024-09-06 12:33:21
js读写cookie
//JS操作cookies方法!
//写cookies
function setCookie(name,value)
{
var Days = 30;
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
//读取cookies
function getCookie(name)
{
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)) return unescape(arr[2]);
else return null;
}
//删除cookies
function delCookie(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
最新文章
- Protobuf使用规范分享
- url 编码(percentcode 百分号编码)(转载)
- 【转】cloudera新增用户权限配置
- linux安装IPython四种方法
- winform 加密 解密 分类: WinForm 2014-05-16 15:05 400人阅读 评论(0) 收藏
- DB2中coalesce函数的应用
- huffman压缩解压文件【代码】
- sqlite的几种访问方法
- mysql表空间加密 keyring encryption
- WebService发布到IIS
- java判断字符串中是否包含中文 过滤中文
- 停止一个java的线程执行
- 尼康G镜头与D镜头的差别
- 使用spring提供的ReflectionUtils简化项目中反射代码的复杂性
- Java并发编程里的volatile。Java内存模型核CPU内存架构的对应关系
- BZOJ 2763 飞行路线(分层图最短路)题解
- Log4J 配置文件模板及代码说明
- 点击button触发onclick事件判空后依旧自动跳转
- face++ API接口调用
- Educational Codeforces Round 56 (Rated for Div. 2) E(1093E) Intersection of Permutations (树套树,pb_ds)
热门文章
- Selenium和PhantomJS
- ssm中的注解
- 别被调查汇总郁闷到——有Excel呢!
- SpringCloud微服务实战——搭建企业级开发框架(三十四):SpringCloud + Docker + k8s实现微服务集群打包部署-Maven打包配置
- CF667A Pouring Rain 题解
- CF177A1/A2 Good Matrix Elements 题解
- 【LeetCode】Integer to English Words 解题报告
- 【九度OJ】题目1175:打牌 解题报告
- 【LeetCode】137. Single Number II 解题报告(Python)
- 【LeetCode】852. Peak Index in a Mountain Array 解题报告(Python)