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>
  • 相关阅读:
    URL Rewrite
    Visual Studio调试Asp程序
    IE6下雪碧图多次请求fix方法
    使用antixss防御xss
    字典及其增删改查,解构用法
    逻辑运算,编码问题
    字符串数据类型及其用法
    数据类型,if 语句,while语句
    列表和字典循环遍历时的删除问题,集合
    列表,及其增删改查,元组
  • 原文地址:https://www.cnblogs.com/mayufo/p/4243823.html
Copyright © 2011-2022 走看看