let cookieValue=null
let cookies=document.cookie.split('')
for(var i=0i<cookies.lengthi++){
let cookie=cookies[i].trim()去掉前后的空格
if(cookie.substring(0,name.length+1)==(name+'=')){
cookieValue=decodeURICompoent(cookie.substring(name.length+1))
break
}
}
return cookieValue
}、
1、获取所有cookie
function getCookies() {var showAllCookie = ''
if(!document.cookie == ''){
var arrCookie = document.cookie.split(' ') //用spilt(' ')切割所有cookie保存在数组arrCookie中
var arrLength = arrCookie.length
for(var i=0 i<arrLength i++) {
showAllCookie += 'c_name:' + unescape(arrCookie[i].split('=')[0]) + 'c_value:' + unescape(arrCookie[i].split('=')[1]) + '<br>' 9
}
return showAllCookie
}
}
2、通过名称读取cookie
function getCookie(name){
var arr,reg=new RegExp("(^| )"+name+"=([^]*)(|$)")
if(arr=document.cookie.match(reg))
return unescape(arr[2])
else
return null
}