js 根据key 获取cookie 里的value
可以使用以下方法:
function getCookieValue(key) {
const cookies = document.cookie.split("; ");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].split("=");
if (cookie[0] === key) {
return cookie[1];
}
}
return "";
}
使用示例:
const cookieValue = getCookieValue("myCookieKey");
console.log(cookieValue);
原文地址: https://www.cveoy.top/t/topic/bgbC 著作权归作者所有。请勿转载和采集!