document.cookie = key=''; expires=${new Date(new Date().getTime() + new Date().setTime(-1 * 1000 * 3600 * 24)).toUTCString()}
我查了下, 说设置过期时间, 但是试了下没成功
给我你的怀抱2017-05-24 11:33:56
这是一个已有成熟解决方案的问题。
function deleteAllCookies() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
}