【发布时间】:2013-11-17 09:11:21
【问题描述】:
我正在处理此代码.. 并且可以在所有浏览器中工作,除了 chrome。 我想每 24 小时为每个 IP 显示 div(A) 1 次。显示该 div(A) 后,我想在每次该 ip 访问我的页面时显示另一个 div(B)。 这是我的代码
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript" src="https://github.com/carhartl/jquery-cookie/raw/master/jquery.cookie.js"></script>
<script type="text/javascript">
$(document).ready(function() {
if( $.cookie('showOnlyOne') ){
//it is still within the day
//hide the div
$('#showOnlyOnceADay').hide();
$('#showothertimes').show();
} else {
//either cookie already expired, or user never visit the site
//create the cookie
$.cookie('showOnlyOne', 'showOnlyOne', { expires: 1 });
//and display the div
$('#showOnlyOnceADay').show();
$('#showothertimes').hide();
}
});
</script>
</head>
<body>
<div id="showOnlyOnceADay">
Div(A)
</div>
<div id="showothertimes">
Div(B)
</div>
</body>
在 Chrome 中总是同时显示两个 div。有什么问题?谢谢!
【问题讨论】:
-
你的控制台里有什么?
-
我想
$.cookie('showOnlyOne')创建的 cookie 没有任何值,因此您可能无法在条件下验证它,所以请尝试if( $.cookie('showOnlyOne') == 'showOnlyOne' ) -
console - 拒绝从 'github.com/carhartl/jquery-cookie/raw/master/jquery.cookie.js' 执行脚本,因为它的 MIME 类型 ('text/plain') 不可执行,并且启用了严格的 MIME 类型检查。 posi.php:1 Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'cookie' - 这是 cookie 的问题。这是我第一次使用 cookie。我正在阅读,但很多人不了解本地 cookie。
-
这个问题是关于什么的?复制? stackoverflow.com/questions/19918221/…??
标签: javascript jquery google-chrome cookies