Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在侧栏中保持所选菜单处于打开状态_Html_Css_Twitter Bootstrap - Fatal编程技术网

Html 如何在侧栏中保持所选菜单处于打开状态

Html 如何在侧栏中保持所选菜单处于打开状态,html,css,twitter-bootstrap,Html,Css,Twitter Bootstrap,我的html外观如下所示,我也在使用引导。我想菜单保持打开我的侧边栏,在我选择了它 因为它不是一页应用程序,请考虑使用这个。您需要在菜单项的每个页面上加载此js和css <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul class="treeview-menu" id="submenu_toggl

我的html外观如下所示,我也在使用引导。我想菜单保持打开我的侧边栏,在我选择了它



因为它不是一页应用程序,请考虑使用这个。您需要在菜单项的每个页面上加载此js和css

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


    <ul class="treeview-menu" id="submenu_toggle">
      <li>
        <a href="tickets.php">
          <i class="fa fa-circle-o sub_menu_fa"></i>Inbox
        </a>
      </li>
      <li>
        <a href="tickets.php?status=assigned">
          <i class="fa fa-circle-o sub_menu_fa"></i>Mine
        </a>
      </li>
      <li>
        <a href="tickets.php?status=overdue">
          <i class="fa fa-circle-o sub_menu_fa"></i>Overdue
        </a>
      </li>
      <li>
        <a href="tickets.php?status=closed">
          <i class="fa fa-circle-o sub_menu_fa"></i>Closed
        </a>
      </li>
    </ul>
    <script>
    $( document ).ready(function() {   
           var url = window.location.href; //get current page url        
             $(".treeview-menu i").each(function() { 
                if (url == (this.href)) {
                       $(this).addClass("active"); //add active class to matched LIst item
                }
            });
        });
    </script>

    <style>
    .active{
      border-bottom:1px solid red;
    }

$(文档).ready(函数(){ var url=window.location.href;//获取当前页面url $(“.treeview menu i”).each(function(){ 如果(url==(this.href)){ $(this).addClass(“活动”);//将活动类添加到匹配的列表项 } }); }); .主动{ 边框底部:1px纯红; }

$(函数(){
//对于引导程序3,使用'show.bs.tab',对于引导程序2,使用下一行中的'show'
$('a[data toggle=“tab”]”)on('show.bs.tab',函数(e){
//保存最新选项卡;如果您更喜欢cookies,请使用cookies:
localStorage.setItem('lastTab',$(this.attr('href'));
});
//转到最新选项卡(如果存在):
var lastTab=localStorage.getItem('lastTab');
如果(最后一个选项卡){
$('[href=“'+lastTab+'“]”)选项卡('show');
}
});

您想要实现什么?我没有得到您想要问的内容。请简要写下您的问题是什么?如何在侧栏中打开我选择的菜单。我希望当我点击我的链接时,它应该被打开和选中,其他链接也是如此。我编辑了你的文章,使代码看起来有意义和整洁。查看我的编辑。谢谢:)
<script>
     $(function() { 
    // for bootstrap 3 use 'shown.bs.tab', for bootstrap 2 use 'shown' in the next line
    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
        // save the latest tab; use cookies if you like 'em better:
        localStorage.setItem('lastTab', $(this).attr('href'));
    });

    // go to the latest tab, if it exists:
    var lastTab = localStorage.getItem('lastTab');
    if (lastTab) {
        $('[href="' + lastTab + '"]').tab('show');
    }
});
 </script>