zoukankan      html  css  js  c++  java
  • dom cookie记录用户名

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <script>
    window.onload = function ()
    {
        var ologin = document.getElementById('login');
        var odel = document.getElementById('del');
        var ousername = document.getElementById('username');
        
        if(getcookie('username'))
        {
            ousername = getcookie('username');
        }
        
        ologin.onclick = function()
        {
            alert('登陆成功')
            setcookie('username',ousername.value,5);
        }
        
        
        
        odel.onclick = function ()
        {
            removecookie('username');
            ousername.value = '';
            
            
        }
        
        function getcookie (key)
        {
            var arr1 = document.cookie.split(';');
            for(var i = 0; i < arr1.length; i++)
            {
                var arr2 = arr1[i].split('=');
                if(key == arr2[0])
                {
                    return decodeURI(arr2[1]);
                }
            }
        }
        
        
        function getcookie (key)
        {
            var arr1 = document.cookie.split(';');
            for(var i = 0; i < arr1.length; i++)
            {
                var arr2 = arr1[i].split('=');
                if(key == arr2[0])
                {
                    return decodeURI(arr2[1]);
                }
            }
        }
        
        function setcookie(key,value,t)
        {
            var oDate = new Date();
            oDate.setDate(oDate.getDate()+t);
            document.cookie = key + ':' + value + ';expires =' + oDate.toGMTString();
        }
        
        
        function removecookie(key)
        {
            setcookie(key,'',-1);
        }
    };
    </script>
    </head>
    
    <body>
    <input type="text" id="username">
    <input type="button" id="login" value="登陆">
    <input type="button" id="del" value="删除">
    </body>
    </html>
  • 相关阅读:
    qt捕鱼达人
    linux通过源码安装gdb
    打造简易http服务器
    linux缓存同步
    NOI之后的碎碎念
    Validate至少有一个不能为空
    IOI 2020 集训队作业
    P6033 [NOIP2004 提高组] 合并果子 加强版 题解
    P3017 [USACO11MAR]Brownie Slicing G 题解
    LOJ #145. DFS 序 2 题解
  • 原文地址:https://www.cnblogs.com/mayufo/p/4243823.html
Copyright © 2011-2022 走看看