【问题标题】:integrating jQuery Cookie集成 jQuery Cookie
【发布时间】:2020-07-13 09:48:17
【问题描述】:

你好,我有这个伪代码:

if(cookie set){
    $("#notification").hide();
}
else {
    $("#notification").show();
}

我怎样才能集成 jQuery Cookie 插件,所以如果它找到一个 cookie 那么它不会显示#notification?

谢谢

【问题讨论】:

    标签: jquery cookies


    【解决方案1】:
    if ($.cookie('whatever')) {
      //exists
    } else {
      //nuthin!
    }
    

    如果您使用的是:http://plugins.jquery.com/project/Cookie

    [编辑]您还可以:

    if ($.cookie('whatever') !== null) {
      //exists
    } else {
      //still nuthin
    }
    

    【讨论】:

      【解决方案2】:

      假设你使用this插件:

      if ($.cookie('the_cookie') ) DO_YOUR_WORK;
      

      【讨论】:

        【解决方案3】:

        这段代码对我有用:

        <script>
            if ($.cookie('whatever')) {
                alert('exists');
            } else {
               alert('not exists');
            }
            //$.cookie('whatever', 'asd'); writing cookie..
        </script>
        

        【讨论】:

          猜你喜欢
          • 2010-09-07
          • 2020-08-31
          • 2023-01-27
          • 2012-10-09
          • 1970-01-01
          • 2019-02-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多