繁体   English   中英

使用jQuery Cookie显示隐藏的内容

[英]Show Hidden Content with jQuery Cookie

我试图在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/

谢谢!

根据文件:

$.cookie('not_existing'); // => undefined

所以在你的:

$.cookie('returningvisitor') === null

应该:

$.cookie('returningvisitor') === undefined

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM