每天展示一次div

Jam*_*mes 4 javascript php jquery

<div class="ads">Some text</div>
Run Code Online (Sandbox Code Playgroud)

想要:

  1. 每个访问者每天显示一次这个块(没有注册)(默认隐藏,cookie检查,应该使用什么?)
  2. 如果块今天已经显示,那么今天就不再显示了
  3. 如果块显示为yeasterday且有一天过去,则再次显示(如何正确检查有一天过去了?)

我怎样才能做到这一点?

具有此功能的网站示例:

http://premiumpixels.com

http://365psd.com

ari*_*ayu 8

我已经创建了使用cookie实现需求的示例代码:

它依赖于jQueryCookie插件.

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
        <script type="text/javascript" src="https://github.com/carhartl/jquery-cookie/raw/master/jquery.cookie.js"></script>
        <script type="text/javascript">                                         
        $(document).ready(function() {
            if( $.cookie('showOnlyOne') ){
                //it is still within the day
                //hide the div
                $('#shownOnlyOnceADay').hide();
            } else {
                //either cookie already expired, or user never visit the site
                //create the cookie
                $.cookie('showOnlyOne', 'showOnlyOne', { expires: 1 });

                //and display the div
                $('#shownOnlyOnceADay').show();
            }
        });
        </script>     
    </head>
    <body>
        <div id="shownOnlyOnceADay">
            This text should only be shown once a day!
        </div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

通过更改系统日期进行测试.