cookiesnotoce=5B225Cu75285Cu62375Cu540d5Cu62165Cu5bc65Cu78015Cu65e05Cu6548225D var noticeStr = decodeURIComponentcookiesnotoce; notimsg = noticeStrreplaceg ; layermsgnotimsg function; consolelognotimsg为什么会输出了undefined
这段代码中,变量名 cookies.notoce 中的 . 可能是一个错误,应该改为 cookies["notoce"] 才能正确获取到 cookie 中的值。另外,如果获取到的值为空,也会输出 undefined。因此,可以在输出前先判断一下值是否为空,如下所示:
if (notimsg) {
layer.msg(notimsg, function(){});
console.log(notimsg);
} else {
console.log("获取 cookie 值失败!");
}
原文地址: https://www.cveoy.top/t/topic/CoH 著作权归作者所有。请勿转载和采集!