我正在尝试在x时间之后为新访问者显示div,并立即显示给回访者。我无法弄清楚为什么这不起作用,并希望有人可以指出错误。
使用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小提琴...... http://jsfiddle.net/mp2E8/1/
谢谢!
答案 0 :(得分:3)
根据文件:
$.cookie('not_existing'); // => undefined
所以在你的:
$.cookie('returningvisitor') === null
应该是:
$.cookie('returningvisitor') === undefined