Javascript操作Cookie[3]
客户端操作Cookie主要使用document.cookie
- 添加Cookie
<script type="text/javascript"> //添加cookie var value ="name=www"; var date = new Date(); date.setDate(date.getDay()+5); document.cookie=value+"; expires="+date.toUTCString(); </script>- 读取Cookie
<script type="text/javascript"> alert(document.cookie); </script>
- 修改Cookie
<script type="text/javascript"> //修改cookie,代码与添加cookie一致 var value ="name=wwwLLLLooo"; var date = new Date(); date.setDate(date.getDay()+5); document.cookie=value+"; expires="+date.toUTCString(); </script>- 删除Cookie
<script type="text/javascript"> //删除Cookie.设置过期时间为昨天即可. var cookieName ="password"; var date = new Date(); date.setDate(date.getDay()-1); document.cookie=cookieName+"=deleted; expires="+date.toUTCString(); </script>