<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Keywords" content="关键字,关键词">
<meta name="Description" content="描述和简介">
<title>Title</title>
<style type="text/css">
*{margin:0;padding:0;}
body,ul,li,ol,dl,dd,p,h1,h2,h3,h4,h5,h6{ margin:0;}
a{text-decoration:none;}
img{border:none;}
ol,ul{list-style:none;}
</style>
</head>
<body>
<div id="box"></div>
<script>
alert(document.cookie);
var date = new Date(2019,0,30,6,0);
document.cookie = "name=洛天;expires="+date.toGMTString();
document.cookie = "age=18;expires="+date.toGMTString();
document.cookie = "sex=nan;expires="+date.toGMTString();
getCookie("sex");
function getCookie(key){
var val = document.cookie.match("\\b" + key + "=([^;]*)(;|$)" );
console.log(val);
return val?val[1]:"";
};
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Keywords" content="关键字,关键词">
<meta name="Description" content="描述和简介">
<title>Title</title>
<style type="text/css">
*{margin:0;padding:0;}
body,ul,li,ol,dl,dd,p,h1,h2,h3,h4,h5,h6{ margin:0;}
a{text-decoration:none;}
img{border:none;}
ol,ul{list-style:none;}
</style>
</head>
<body>
<div id="box">
<p id="p1"></p>
<p id="p2"></p>
</div>
<script>
var op1 = document.getElementById("p1"),
op2 = document.getElementById("p2"),
val = getCookie("Time");
if(val){
op1.innerHTML = "您上次访问的时间是:"+ val;
}else{
op1.innerHTML = "欢迎第一次访问本网站";
};
var date = new Date(),
YY = date.getFullYear(),
MM = date.getMonth(),
DD = date.getDate(),
hh = date.getHours(),
mm = date.getMinutes(),
ss = date.getSeconds(),
time = YY + "年" + MM + "月" + DD + "日" + hh + "点" + mm + "分" + ss + "秒";
op2.innerHTML = "当前时间是: " + time;
setCookie({
Time : time
},2);
function getCookie(key){
var val = document.cookie.match("\\b" + key + "=([^;]*)(;|$)" );
return val?val[1]:"";
};
function setCookie(mJson , time){
var data = new Date(new Date().getTime() + time*24*60*60*1000).toGMTString();
for(var key in mJson){
document.cookie = key+"="+mJson[key]+";expires="+data;
};
};
removeCookie("Time");
function removeCookie(key){
var json = {};
json[key] = "";
setCookie(json,-1)
};
</script>
</body>
</html>