简体   繁体   English

Bootstrap崩溃Cookie无法正常工作

[英]Bootstrap collapse cookies not working

Everytime I clicked on the "collapse" button, it worked but after its refreshed, it doesn't save its state. 每次我单击“折叠”按钮时,它都起作用,但是刷新后,它不会保存其状态。 For example when I collapse a panel and refresh the page, then the panel is left open. 例如,当我折叠面板并刷新页面时,面板保持打开状态。

PS the {$forum['fid']} represents a forum number, which is automatically generated through templates PS {$ forum ['fid']}代表论坛号,它是通过模板自动生成的

HTML 的HTML

<div class="panel panel-default" id="forum">
  <div class="panel-heading"><h3 class="panel-title"><a href="{$forum_url}">{$forum['name']}</a></h3><span class="pull-right"><a href="#forumlist{$forum['fid']}" data-parent="forum" data-toggle="collapse">Toggle</a></span></div>
  <div id="forumlist{$forum['fid']}"  class="panel-collapse collapse in">
  <div class="panel-body panel-default"> 
<div class="panel panel-default" style="margin-bottom: 0px;border:1px solid #2b2b2b;">
<table class="table table-hover">
    <tbody>
{$sub_forums}
    </tbody>
</table>
</div>
  </div>
    </div>
</div>

JS JS

   $(document).ready(function () {
        //when a group is shown, save it as the active accordion group
        $("#forum").on('shown.bs.collapse', function () {
            var active = $("#forum .in").attr('id');
            $.cookie('activeForumGroup', active);
          //  alert(active);
        });
        $("#forum").on('hidden.bs.collapse', function () {
            $.removeCookie('activeForumGroup');
        });
        var last = $.cookie('activeForumGroup');
        if (last != null) {
            //remove default collapse settings
            $("#forum .panel-collapse").removeClass('in');
            //show the account_last visible group
            $("#" + last).addClass("in");
        }
    });

This may be missing 这可能会丢失

<div class="panel-group" id="forum">
<div class="panel panel-default">

changing the ID of each other 互相更改ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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