javascript - 使用 jQuery Cookie 显示隐藏内容

标签 javascript jquery cookies

我试图让一个 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/

相关文章:

javascript - 在渲染之前对 Backbone 集合进行排序

php - 客户无法登录 magento

Codeigniter session 安全

java - 如何从 JSON 转换为 JSONP?

javascript - jquery复选框元素类click

javascript - 将数据ajax发送到php

iOS - 未设置 WebView cookie

javascript - 检测所选元素

javascript - 如何获取选中的复选框值并将其存储在angularjs中的数组变量中?

Javascript 正则表达式反向引用索引