zoukankan      html  css  js  c++  java
  • JS设置cookie,读取cookie,删除cookie

    总结了一下cookie的使用,不全面.都是基础的知识,后期还会再添加.

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
     3 <head>
     4   <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
     5   <title>cookie</title>
     6 </head>
     7 <body>
     8   
     9 </body>
    10 </html>
    11 <script type="text/javascript">
    12 //write cookie
    13 function setCookie(name, value){
    14       var Days=30;
    15       var exp=new Date();
    16       exp.setTime(exp.getTime()+Days*24*60*60*1000);
    17       document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();
    18 }
    19 //reading cookie
    20 function getCookie(){
    21         var arr,reg=new RegExp("(^|)"+name+"([^;]*)(;|$)");
    22         if(arr=document.cookie.match(reg)){
    23                       return unescape(arr[2]); 
    24         }else{
    25                       return null;
    26         }
    27 }
    28 //delete cookie
    29 function delCookie(name){
    30         var exp=new Date();
    31         exp.setTime(exp.getTime()-1);
    32         var cval=getCookie(name);
    33         if(cval!=null){
    34             document.cookie=name+"="+cval+";expires="+exp.toGMTString();
    35         }
    36 }
    37 setCookie("name","liubeimeng");
    38 setCookie("name1","liubeimeng1");
    39 delCookie("name1");
    40 alert(getCookie("name")); 
    41 </script>
  • 相关阅读:
    L6循环神经网络
    L5语言模型与数据集
    L4文本预处理
    L2 Softmax与分类模型
    L3 多层感知机
    L1线性回归
    P4语法(4)Control block
    机器学习笔记(4)Logistic回归
    [CF] Sasha and One More Name
    机器学习笔记(3)多变量线性回归
  • 原文地址:https://www.cnblogs.com/liubeimeng/p/4956416.html
Copyright © 2011-2022 走看看