如代码:
<script type="text/javascript"> document.cookie="name=zhangsan; "; document.cookie="age=16; "; function setCookie(key,value,t) {//t为秒 var exp = new Date(); exp.setTime(exp.getTime() + t*1000); document.cookie = key + '=' + value + ';expires=' + exp.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>