<title>W3Cschool教程(w3cschool.cn)</title>
function setCookie(cname,cvalue,exdays){
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname+"="+cvalue+"; "+expires;
function getCookie(cname){
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
var user=getCookie("username");
alert("Welcome again " + user);
user = prompt("Please enter your name:","");
if (user!="" && user!=null){
setCookie("username",user,30);
<body onload="checkCookie()"></body>