Javascript操作Cookie[3]

客户端操作Cookie主要使用document.cookie

  1. 添加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>
  2. 读取Cookie
        <script type="text/javascript">
            alert(document.cookie);
        </script>
  3. 修改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>
  4. 删除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>
posted @ 2010-08-04 22:43  Localhost  阅读(418)  评论(0编辑  收藏  举报