如何在JavaScript中删除Cookie?
有时您会想要删除一个cookie,以便随后尝试读取该cookie不会返回任何内容。为此,您只需要将到期日期设置为过去的某个时间即可。
示例
请尝试以下示例。它说明了如何通过将cookie的过期日期设置为当前日期后一个月来删除它。
<html>
<head>
<script>
<!--
function WriteCookie() {
var now = new Date();
now.setMonth( now.getMonth() - 1 );
cookievalue = escape(document.myform.customer.value) + ";"
document.cookie="name=" + cookievalue;
document.cookie = "expires=" + now.toUTCString() + ";"
document.write("Setting Cookies : " + "name=" + cookievalue );
}
//-->
</script>
</head>
<body>
<form name="myform" action="">
Enter name: <input type="text" name="customer"/>
<input type="button" value="Set Cookie" onclick="WriteCookie()"/>
</form>
</body>
</html>热门推荐
8 年月日祝福语简短
10 国庆中秋祝福语简短搞笑
11 红颜生日祝福语简短独特
12 长辈生日祝福语简短女性
13 Q穷人结婚祝福语简短
14 中秋妈妈生日祝福语简短
15 三八简短祝福语给婆婆
16 简短大气的狗年祝福语
17 高考送考祝福语简短
18 传统新年祝福语大全 简短