添加要切换的cookie

Adding cookies to toggle

本文关键字:cookie 添加      更新时间:2023-09-26

所以我试图将cookie添加到我网站的"toggle"部分,问题是,我尝试了其他方法,它们确实有效,但要么图标不同步,要么在togglediv内的脚本搞砸了。那么我该如何解决这些问题呢?非常感谢!

jQuery(document).ready(function ($) {
    $("#top4trigger").click(function () {
        $("#top4hide").slideToggle("slow")
        $("i", this).toggleClass("fa fa-chevron-up fa fa-chevron-down")
    });
});

你需要jQuery cookie来工作。

$.cookie('your_cookie_name', 'your_cookie_value', { path: '/' });

你可以尝试这样做:

if ($(this).hasClass("class-name")) {
    // add and remove classes and cookie
  } else {
    // add and remove classes and cookie
}