0

我是 JavaScript 新手。如果之前访问过网站,我尝试制作一个显示 cookie 的 cookie,否则询问名称。我不知道为什么脚本不起作用。请帮我调试。`

<script type="text/javascript"> 
//-----------
function check()
{
if(document.cookie.length>0){
return document.cookie
}
else
return ""
}
//---------
function get(){
var today=new date()
today.setDate(today+1)
var name=check()
if(name=="")
{name=prompt("name?","")
document.cookie="username="+name+";expires="+today.toUTCString()
}
else
document.write("welcome back"+document.cookie)
}
</script>
</head>
<body >
<script type="text/javascript"> 
get();
</script>
</body> 
</html>`<html> 
this is so frustrating! Passerby already edited the body of this post; your edit must be more substantive to override the current edit.
4

1 回答 1

1
var today=new Date();

与资本 D。

更新:在localhost 上运行此代码。

于 2013-07-10T09:27:19.357 回答