<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>注册</title> <script> /*setCookie("friend","大表哥",2.5*60*1000); setCookie("userName","admin123");*/ function setCookie(cookieName,cookieVal,lasttime) { //cookieName cookieValue //expires 过期时间 path / var time = new Date().getTime();//获取当前的日期时间 //15分钟过期 if(lasttime) { time+=lasttime; } else { time += 15*60*1000; } time = new Date(time); //再加上一个编码 document.cookie = cookieName+"="+cookieVal+";expires="+time+‘;path=/‘; } setCookie(friend,大表哥,2.5*60*1000) //userName rName function getCookie(cookieName) { //get 获取所有cookie var strs = document.cookie; //将cookie字符串拆分数组 var cookies = strs.split(‘; ‘) for(var i=0;i<cookies.length;i++) { //[‘friend=大表哥‘ ,‘userName=admin123‘] if(cookies[i].indexOf(cookieName+‘=‘)==0) { //代表存在一个cookie return cookies[i].split(‘=‘)[1]; } } } var n = getCookie("friend"); console.info("获取cookie",n) function delCookie() { } </script> </head> <body> <div> <lable>注册账号:</lable> <input type="text"> </div> <div> <lable>密码:</lable> <input type="text"> </div> <div> <lable>重复密码:</lable> <input type="text"> </div> <p> <button>注册</button> </p> </body> </html>
时间: 2024-11-09 18:27:47