1、简单的删除cookie
//删除cookiefunction deleteCookie(name){
var date=new Date()
date.setTime(date.getTime()-10000)
document.cookie=name+"=v expires="+date.toGMTString()
}
2、设置访问路径的cookie删除
/*** js 删除 http cookie
* @param name 名字
* @param path 路径
* @param domain 域名
*/
function deleteCookie(name,path,domain){
if(getCookie(name)) document.cookie= name+'='+
((path)?'path='+path:'')+
((domain)?'domain='+domain:'') +
'expires=Thu,01-Jan-1970 00:00:01 GMT'
}
/**
* js取得http cookie
* @param name cookie名字
*/
function getCookie(name) {
var start = document.cookie.indexOf( name + "=")
var len = start + name.length + 1
if((!start)&&(name!=document.cookie.substring(0,name.length))){
return null
}
if ( start == -1 ) return null
var end = document.cookie.indexOf( '', len )
if ( end == -1 ) end = document.cookie.length
return unescape( document.cookie.substring( len, end ) )
}
1、首先可以通过控制台或输出cookie的值先核实cookie的key是不是正确的。2、是否是通过setCookie(cookie的key, "", -1)来删除设置cookie的方法名?