zoukankan      html  css  js  c++  java
  • cookie学习

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script>

    //设置cookie,(名称,值,过期时间天为单位)
    function setCookie(name,value,iDay){
    var oDate=new Date();
    //设置时间
    oDate.setDate(oDate.getDate()+iDay);
    document.cookie=name+'='+value+';expires='+oDate;
    }

    //读取cookie(名称)
    function getCookie(name){
    //切割成数组
    var arr= document.cookie.split('; ');
    for(var i=0;i<arr.length;i++){
    //再次切割成数组
    var arr2 =arr[i].split('=');
    if(arr2[0]== name ){
    return arr2[1];
    }
    }
    return ;//没有找到为空
    }
    //删除cookie值
    function removeCookie(name){
    setCookie(name,1,-1);
    }

    //用户记住用户名
    window.onload=function(){
    var oForm=document.getElementById("form1");
    var oUser=document.getElementsByName('user')[0];
    oForm.onsubmit=function(){
    //设置cookie
    setCookie('user',oUser.value,14);
    };
    //读取cookie
    oUser.value=getCookie('user');
    }


    </script>

    </head>


    <body>
    <form id="form1" action="http://www.baidu.com">
    用户名:<input type="text" name="user" /><br />
    密码:<input type="password" name="psaa" /><br />
    <input type="submit" value="登陆" />
    </form>


    </body>
    </html>

  • 相关阅读:
    msql 触发器
    微信模板消息推送
    微信朋友朋友圈自定义分享内容
    微信退款
    异步调起微信支付
    微信支付
    第一次作业
    【Linus安装MongoDB及Navicat】
    【前端】ES6总结
    【开发工具】Pycharm使用
  • 原文地址:https://www.cnblogs.com/xurui01/p/4509848.html
Copyright © 2011-2022 走看看