码迷,mamicode.com
首页 > Web开发 > 详细

Js cookie操作

时间:2014-12-03 17:07:55      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   java   for   on   

如代码:

<script type="text/javascript">
document.cookie="name=zhangsan; ";
document.cookie="age=16; ";

function setCookie(key,value,t) {
        var oDate = new Date();
        oDate.setDate(oDate.getDate() + t);
        document.cookie = key + ‘=‘ + value + ‘;expires=‘ + oDate.toGMTString()+";path=/;domain=.9888.cn";
    }

function getCookie(key) {//获取指定名称的cookie的值 
    var arr1 = document.cookie.split(‘; ‘);
    for (var i=0; i<arr1.length; i++) {
        var arr2 = arr1[i].split(‘=‘);
        if (arr2[0] == key) {
            return arr2[1];
        }
    }
}

//删除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(); 
}

</script>

 

Js cookie操作

标签:style   blog   io   ar   color   sp   java   for   on   

原文地址:http://www.cnblogs.com/thinksasa/p/4140440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!