我试图让一个 div 在 x 时间后显示给新访客,并立即显示给回访者。我不明白为什么这行不通,希望有人能指出错误。
使用 jQuery Cookie 插件:https://github.com/carhartl/jquery-cookie
//Make Hidden Content Visible
jQuery(document).ready(function($) {
// set the delay with the following vars
var hour = 0;
var minutes = 0;
var secs = 7;
var thisdelay = (hour*60*60*1000) + (minutes * 60 * 1000) + (secs * 1000);
//checks a cookie value
//If no cookie found, add a cookie for the next visit
if($.cookie('returningvisitor') === null) {
var duration = 1; // days until cookie expires
$.cookie('returningvisitor', 'true', { expires: duration});
//then wait until delay to display
$(".hideshow").delay(thisdelay).fadeIn("fast");
}
else {
//immediately display the content
$(".hideshow").css("display", "block");
}
});
和...
<div class="hideshow" style="display:none;"><p>Hello World</p></div>
还有 JS fiddle …… http://jsfiddle.net/mp2E8/1/
谢谢!
最佳答案
根据文档:
$.cookie('not_existing'); // => undefined
所以在你的:
$.cookie('returningvisitor') === null
应该是:
$.cookie('returningvisitor') === undefined
关于javascript - 使用 jQuery Cookie 显示隐藏内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20426106/