如何使用JavaScript清除所有cookie?
要使用JavaScript清除所有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>热门推荐
10 送给员工美好祝福语简短
11 高考已上岸祝福语简短
12 猪年元旦祝福语简短创意
13 小红书生日祝福语简短
14 生日祝福语简短明了 同事
15 高中升学宴祝福语简短
16 舅舅大婚文案祝福语简短
17 工人生日祝福语简短
18 给舍友送祝福语简短