使用document.cookies.includes(“ cookie = value”)不会成功吗?我看到大量复杂的功能,例如:
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
为什么需要这个?使用document.cookie.includes()检查cookie是否有问题?