目前,我正试图使用cookie插件将变量userScore存储在cookie userScoreCookie中。当我console.log时,打印的数据的内容是“未定义的”。是什么引起的?
var cookieValue;
var userScore = 0;
$.cookie('userScoreCookie', 'userScore', {path: '/',expires: 365});
cookieValue = $.cookie("userScoreCookie");
console.log("cookie score: " + cookieValue);<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
发布于 2016-01-19 12:16:17
当页面被本地托管时,Chrome不能使用cookie,改为firefox来测试cookie,解决了这个问题
发布于 2016-01-04 13:16:36
将下面的内容粘贴到链接中,以检查其hide
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
var cookieValue;
var userScore = 0;
$.cookie('userScoreCookie', "test");
cookieValue = $.cookie("userScoreCookie");
console.log("cookie score: " + cookieValue );
alert(cookieValue )
});
});
</script>
</head>
<body>
<p>Click me</p>
</body>
</html>https://stackoverflow.com/questions/34591667
复制相似问题