【发布时间】:2017-09-12 18:03:58
【问题描述】:
我试图通过调用一个简单的函数来保存一个 cookie。以下是我的代码:
<html>
<head></head>
<body>
<button onclick="alpha()">Click Me</button>
<script>
function alpha(){
var now = new Date();
now.setMonth(now.getMonth() - 1);
document.cookie="name=" + "PeterMartin";
document.cookie = "expires=" + now.toUTCString() + ";"
}
</script>
</body>
</html>
我从以下网站获得了帮助:
https://www.tutorialspoint.com/javascript/javascript_cookies.htm
但是,我可以看到他们的功能可以将 cookie 保存在我的本地,但我无法通过我自己的更多自定义功能找到相同的功能。基本上,我们都在做同样的事情,但是为什么我的代码无法像下图那样保存 cookie:
【问题讨论】:
标签: javascript html cookies