简体   繁体   中英

How to create an if statement with jquery.cookie

So I have this code down below and I now I want to implement it with jquery cookie to fire this code only once in a month, how can I accomplish this?

$(function() {
    var $follow = $(".follow-1");
    if (!$follow.hasClass("active")) {
        $follow.click();
    }
});

You likely mean something like this:

$(function() {
   var cook = $.cookie("seen"); // get the cookie
   if (!cook) { // if no cookie show
    var $follow = $(".follow-1");
    if (!$follow.hasClass("active")) {
       $follow.click();
    }
    $.cookie("seen","yes",{"expires":30}); // set cookie to expire in 30 days
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM