cookie测试取值等(亲自测试)

xiaoxiao2021-02-28  86

cookie测试取值等

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>cookies test</title> <style> .mod_lost_child{margin:0 auto;} </style> </head> <body> <h1>HELLO,WORLD FIRST</h1> <h2> <input type='button' οnclick="setvalue()" style="font-size:20px" value='setcookies'> </h2> <script> function setvalue(){ var timestamp = Date.parse(new Date()); setCookie('username','FIRST Cookie...value:'+timestamp,'30') alert('setvalue sucess:'+'FIRST Cookie...value:'+timestamp); } function setCookie(cookieName, cookieValue, expiredays) { var date=new Date(); date.setDate(date.getDate()+expiredays); document.cookie=cookieName+'='+cookieValue+'; expries='+date.toGMTString()+'path=/'; } function getCookie(cookieName) { var cookies=document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var userData=cookies[i].split('='); if (userData[0]==cookieName) { return userData[1]; }; }; return ''; } </script> <br> <a href="cookies.html"><h3>setCookie</h3></a> <a href="cookies_value.html"><h3>getCookie</h3></a> </body> </html>

1

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>cookies test</title> <style> .mod_lost_child{margin:0 auto;} </style> </head> <body> <h1>HELLO,WORLD cookies_value:<input type='text' style="width:700px;font-size:20px" id='valueid' /></h1> <script> function setCookie(cookieName, cookieValue, expiredays) { var date=new Date(); date.setDate(date.getDate()+expiredays); document.cookie=cookieName+'='+cookieValue+'; expries='+date.toGMTString()+'path=/'; } function getCookie(cookieName) { var cookies=document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var userData=cookies[i].split('='); if (userData[0]==cookieName) { return userData[1]; }; }; return ''; } function setvalue(){ console.info('111111111111111111'); document.getElementById('valueid').value=getCookie('username'); } setvalue(); </script> <br> <a href="cookies.html"><h3>setCookie</h3></a> <a href="cookies_value.html"><h3>getCookie</h3></a> </body> </html>
转载请注明原文地址: https://www.6miu.com/read-2632709.html

最新回复(0)