cookie操作
来源:互联网 发布:广州淘宝培训汇学好 编辑:程序博客网 时间:2024/06/07 15:38
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';'); //把cookie分割成组
for(var i=0;i < ca.length;i++) {
var c = ca[i]; //取得字符串
while (c.charAt(0)==' ') { //判断一下字符串有没有前导空格
c = c.substring(1,c.length); //有的话,从第二位开始取
}
if (c.indexOf(nameEQ) == 0) { //如果含有我们要的name
return unescape(c.substring(nameEQ.length,c.length)); //解码并截取我们要值
}
}
return false;
}
//清除cookie
function clearCookie(name) {
setCookie(name, "", -1);
}
//设置cookie
function setCookie(name, textue, seconds) {
seconds = seconds || 0; //seconds有值就直接赋值,没有为0,这个根php不一样。
var expires = "";
if (seconds != 0 ) { //设置cookie生存时间
var date = new Date();
date.setTime(date.getTime()+(seconds*1000));
expires = "; expires="+date.toGMTString();
}
document.cookie = name+"="+escape(textue)+expires+";path=/"; //转码并赋值
}
var nameEQ = name + "=";
var ca = document.cookie.split(';'); //把cookie分割成组
for(var i=0;i < ca.length;i++) {
var c = ca[i]; //取得字符串
while (c.charAt(0)==' ') { //判断一下字符串有没有前导空格
c = c.substring(1,c.length); //有的话,从第二位开始取
}
if (c.indexOf(nameEQ) == 0) { //如果含有我们要的name
return unescape(c.substring(nameEQ.length,c.length)); //解码并截取我们要值
}
}
return false;
}
//清除cookie
function clearCookie(name) {
setCookie(name, "", -1);
}
//设置cookie
function setCookie(name, textue, seconds) {
seconds = seconds || 0; //seconds有值就直接赋值,没有为0,这个根php不一样。
var expires = "";
if (seconds != 0 ) { //设置cookie生存时间
var date = new Date();
date.setTime(date.getTime()+(seconds*1000));
expires = "; expires="+date.toGMTString();
}
document.cookie = name+"="+escape(textue)+expires+";path=/"; //转码并赋值
}
阅读全文
1 0
- Cookie操作
- Cookie操作
- Cookie操作
- cookie 操作
- Cookie操作
- Cookie操作
- 操作cookie
- 操作Cookie
- cookie操作
- Cookie 操作
- 操作cookie
- cookie操作
- Cookie操作
- 操作cookie
- Cookie操作
- 操作cookie
- cookie操作
- cookie操作
- 安卓高手之路之图形系统(6)ListView继续
- buider模式的缺陷
- HDU-1754 I Hate It (线段树)(仍有BUG未改)
- 可扩展性的builder模式的构建方法
- Bagging 与Boosting
- cookie操作
- 安卓中实现两端对齐,中间fill_parent的方法
- tcpdump抓包
- 双端队列
- 网络杂谈, Docker, MongoDB
- 编程实现一个单链表节点的删除
- Android输入法框的梳理
- KMP算法之我见
- c++对象模型