JavaScript 删除cookie的问题
window.onload=cookieDelete;functioncookieDelete(){varcookieCt=0;if(document.cookie!="...
window.onload = cookieDelete;
function cookieDelete() {
var cookieCt = 0;
if (document.cookie != "" && confirm("Do you want to delete the cookies?")) {
var thisCookie = document.cookie.split("; ");
cookieCt = thisCookie.length;
var expireDate = new Date();
expireDate.setDate(expireDate.getDate()-1);
for (var i=0; i<cookieCt; i++) {
var cookieName = thisCookie[i].split("=")[0];
/*为什么cookieName + "=;" 这句话没读明白,不是cookieName = cookieValue吗? 没有cookieValue啊。
能不能帮我把document.cookie = cookieName + "=;expires=" + expireDate.toGMTString();
这一整句话读一下?*/
document.cookie = cookieName + "=;expires=" + expireDate.toGMTString();
}
}
document.getElementById("cookieData").innerHTML = "Number of cookies deleted: " + cookieCt;
} 展开
function cookieDelete() {
var cookieCt = 0;
if (document.cookie != "" && confirm("Do you want to delete the cookies?")) {
var thisCookie = document.cookie.split("; ");
cookieCt = thisCookie.length;
var expireDate = new Date();
expireDate.setDate(expireDate.getDate()-1);
for (var i=0; i<cookieCt; i++) {
var cookieName = thisCookie[i].split("=")[0];
/*为什么cookieName + "=;" 这句话没读明白,不是cookieName = cookieValue吗? 没有cookieValue啊。
能不能帮我把document.cookie = cookieName + "=;expires=" + expireDate.toGMTString();
这一整句话读一下?*/
document.cookie = cookieName + "=;expires=" + expireDate.toGMTString();
}
}
document.getElementById("cookieData").innerHTML = "Number of cookies deleted: " + cookieCt;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询