zoukankan      html  css  js  c++  java
  • cookie的简单应用

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题pj文档</title>
    <style>
     
    </style>
    <script>
    window.onload=function()
    {
    	var oText=document.getElementById('username')
    	var oLogin=document.getElementById('btn1');
    	var oBtn=document.getElementById('btn2');
    	
    
    
    if ( getCookie('username') ) {
    		oText.value = getCookie('username');
    	}
    		oLogin.onclick = function() {
    		
    		alert('登陆成功');
    		setCookie('username', oText.value, 5);
    		
    	}
    		oBtn.onclick=function()
    		{
    			removeCookie('username');
    			oText.value='';
    		}
    };
    
    
    
    function setCookie(key, value, t) {
    	var oDate = new Date();
    	oDate.setDate( oDate.getDate() + t );
    	document.cookie = key + '=' + value + ';expires=' + oDate.toGMTString();
    }
    
    function getCookie(key) {
    	var arr1 = document.cookie.split('; ');
    	for (var i=0; i<arr1.length; i++) {
    		var arr2 = arr1[i].split('=');
    		if ( arr2[0] == key ) {
    			return decodeURI(arr2[1]);
    		}
    	}
    }
    
    function removeCookie(key) {
    	setCookie(key, '', -1);
    }
    </script>
    </head>
    
    <body>
    	<input id="username" type="text"></input> 
    	
    	<input type="button" id="btn1" value="登录"></input>
    	<input type="button" id="btn2" value="删除"></input>
    	
    </body>
    </html>
    

      

  • 相关阅读:
    NOIp2018集训test-9-23
    NOIp2018集训test-9-22(am/pm) (联考三day1/day2)
    NOIp2018集训test-9-21(am/pm)
    NOIp2018集训test-9-19(am&pm)
    day41.txt
    day40表关系
    day39
    day38数据库
    day37
    day36
  • 原文地址:https://www.cnblogs.com/hduhdc/p/5424681.html
Copyright © 2011-2022 走看看