簡體   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