【问题标题】:if this cookie !== null then do this如果这个 cookie !== null 然后这样做
【发布时间】:2014-07-18 05:47:32
【问题描述】:

carhartl 的插件 jquery-cookie 有一些问题......只是在让粘性页脚出现方面......

这个想法是有一个始终位于页面底部的stickfooter,如果以其他方式关闭。很简单。

因此,十字的 onclick 触发了两件事:隐藏stickfooter div 并附加会话cookie。

现在,它会弹出一瞬间,然后无限期地隐藏起来。但是cookie尚未设置。

<script type="text/javascript">
jQuery(document).ready(function () {

    if (jQuery.cookie('stickyNewsClosed') === null) {
        jQuery('.stickyFooter').show();
    }
        if (jQuery.cookie('stickyNewsClosed') !== null) {
            jQuery('.stickyFooter').hide();
        }
});
</script>

<script type="text/javascript">
function closeSticky(){
    jQuery('.stickyFooter').hide();
    jQuery.cookie('stickyNewsClosed', 'yup', {
                path: '/'
            });
}
</script>

也许使用 .css() jquery 方法而不是 .hide() / .show() ?

【问题讨论】:

    标签: javascript jquery cookies jquery-cookie


    【解决方案1】:

    您好,请看这里:http://plnkr.co/edit/yaXgcEsMuNaGu5dQJnL0?p=preview

    jQuery(document).ready(function() {
    console.log(jQuery.cookie('stickyNewsClosed'));
      if (jQuery.cookie('stickyNewsClosed') === undefined) {
        jQuery('.stickyFooter').show();
      }
     else if (jQuery.cookie('stickyNewsClosed') !== null) {
        jQuery('.stickyFooter').hide();
      }
    });
    
    
    
    function closeSticky() {
    
      jQuery('.stickyFooter').hide();
      jQuery.cookie('stickyNewsClosed', 'yup', {
        path: '/'
      });
    }
    

    【讨论】:

    • 啊!一个 else if - 太棒了!
    猜你喜欢
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-19
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    相关资源
    最近更新 更多