我的脚本使用 JavaScript 设置了一个名为 stop_mobi 的 cookie。然后,当用户单击带有 onclick 事件的链接时,我尝试删除 cookie,但是当我对此进行测试时,cookie 没有被删除。任何指向我哪里出错的指针都将不胜感激。谢谢。
<script type="text/javascript">
// set stop_mobi cookie for test purposes
function setCookie(cookieName, cookieValue, nDays) {
var today = new Date();
var expire = new Date();
if (nDays == null || nDays == 0) nDays = 1;
expire.setTime(today.getTime() + 3600000 * 24 * nDays);
document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
}
setCookie("stop_mobi", "yes", "5");
function deleteCookie(name) {
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
alert('Cookie deleted');
}
</script>
<a href="" onclick="deleteCookie('stop_mobi');">Delete cookie</a>