如何使用 jquery.cookie 创建 if 语句

How to create an if statement with jquery.cookie

下面有这段代码,现在我想用 jquery cookie 实现它,每月只触发一次这段代码,我该如何实现?

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

你的意思可能是这样的:

$(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
  }
});