码迷,mamicode.com
首页 > 其他好文 > 详细

用cookie记录上次登录的用户名

时间:2020-05-31 21:36:44      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:tran   ansi   密码   org   tle   BMI   ofo   public   cti   

<!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" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>用cookie记录上次登录的用户名</title>
    <script>
       function setCookie(name,value,iDay){
        var oDate=new Date();
        oDate.setDate(oDate.getDate()+iDay);

        document.cookie=name+=+value+;expires=+oDate;
       }

       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 ‘‘;
       }

       function removeCookie(name){
        setCookie(name,1,-1);
       }


       window.onload=function(){
           var oForm=document.getElementById(form1);
           var oUser=document.getElementById(user)[0];

           oForm.onsubmit=function(){
                setCookie(user,oUser.value,14);
           };

           oUser.value=getCookie(user);
       };
       
    </script>
    </head>

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

 

用cookie记录上次登录的用户名

标签:tran   ansi   密码   org   tle   BMI   ofo   public   cti   

原文地址:https://www.cnblogs.com/sunnywindycloudy/p/13021454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!