<!DOCTYPE html
>
<html lang
="en">
<head
>
<meta charset
="UTF-8">
<title
>Document
</title
>
<script type
="text/javascript">
</script
>
</head
>
<body
>
用户名:
<input type
="text">
密码:
<input type
="password">
<label
><input type
="checkbox">七天免登录
</label
>
<input type
="button" value
="登录">
<script type
="text/javascript">
var aInput
= document
.getElementsByTagName("input");
if(getCookie("username")){
aInput
[0].value
= getCookie("username");
aInput
[1].value
= getCookie("password");
}
aInput
[3].onclick = function(){
var username
= aInput
[0].value
;
var password
= aInput
[1].value
;
if (aInput
[2].checked
) {
setCookie("username", username
, 7);
setCookie("password", password
, 7);
}
}
function setCookie(name
, value
, day
){
var oDate
= new Date();
oDate
.setDate(oDate
.getDate() + day
);
document
.cookie
= name
+ "=" + value
+ ";expires=" + oDate
;
}
function getCookie(name
){
var str
= document
.cookie
;
var arr
= str
.split("; ");
for(var i
= 0; i
< arr
.length
; i
++){
var arr1
= arr
[i
].split("=");
if(arr1
[0] == name
){
return arr1
[1];
}
}
}
function removeCookie(name
){
setCookie(name
, 1, -1);
}
</script
>
</body
>
</html
>
有问题,浏览器没反应,但也没报错。。。 cookie里没有数据
转载请注明原文地址: https://mac.8miu.com/read-510419.html