首页 > 代码库 > Js cookie操作

Js cookie操作

如代码:

<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操作