【问题标题】:How to set cookie for close button如何为关闭按钮设置cookie
【发布时间】:2017-11-21 10:17:58
【问题描述】:

我想在按下关闭按钮时设置cookie,以防止对话框再次打开。

这是我的代码:

<div class="card">
  <span class="clickable" data-effect="fadeOut"><i class="fa fa-times"></i></span>
    <div class="card-blockquote">Free shipping </div>
</div>

<script>
jQuery('.close-icon').on('click',function() {
  jQuery(this).closest('.card').fadeOut();
})
</script>

更新:

我添加了这个库:

<action method="addLinkRel"><rel>text/javascript</rel><href>https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.2/js.cookie.js</href></action>

我使用以下代码:

 $.cookie('card', 'card', { expires: 7 });

我在控制台中有:

TypeError: $.cookie is not a function

【问题讨论】:

    标签: javascript jquery cookies


    【解决方案1】:

    您可以使用 cookie 生成器。 here

    <script>
    jQuery('.close-icon').on('click',function() {
      jQuery(this).closest('.card').fadeOut();
    $.jCookies({
        name : 'Your_cookie_Namee',
        value : {cookie values}
    });
    
    })
    </script>
    

    所以如果要使用localstorage,可以使用this

    【讨论】:

    • 谢谢,但我更喜欢使用本地存储或 jquery cookie
    • @StefanD。使用this
    • 如何为我的代码设置 1 天的 cookie?实际上什么是名称:'Your_cookie_Namee',值是:{cookie values}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-10
    • 2019-09-14
    • 1970-01-01
    • 2020-06-27
    • 2017-04-16
    • 2014-03-22
    • 1970-01-01
    相关资源
    最近更新 更多