1

I am having lengthy structure of bootstrap theme classes.

This is menu i am designing.

Dashboard select with current '.active' class-

Have this code for this menu bar design in bootstrap-

   <div class="navbar navbar-fixed-top navbar-inverse">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"><span
                        class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                    </a><a class="brand" href="#">My Menu</a>
                    <div class="nav-collapse">
                        <ul class="nav">
                            <li class="active"><a  href="/Home/Dashboard"><i class="icon-home icon-white"></i>Dashboard</a></li>
                            <li ><a href="#" id="taskMainLink">Task</a></li>

                            <li><a href="#" id="contactMainLink">Contact</a></li>

                            <li><a href="#" id="appointmentMainLink">Appointment</a></li>

                            <li><a href="#" id="projectMainLink">Project</a></li>

                            <li><a href="#" id="salesMainLink">Sales</a></li>

                        </ul>

Now Issue

I want each tab to be active on mouseclick and other tabs should be in original state. Current active class is dashboard by default i did.

Structure i am following for each time i click on any tab-

$('.navbar.navbar-fixed-top.navbar-inverse>.container-fluid>.nav-collapse>.nav').click(function(){
$(this).find('li').removeClass('active');
$(this).addClass('active');
});

Am i going right class into class? Please suggest me right solution if i am wrong here.

4

3 回答 3

3

尝试这个:

$('ul.nav li a').click(function(){
    $(this).parent().parent().children('.active').removeClass('active');
    $(this.parentNode).addClass('active');
    return false;
});
于 2013-02-09T12:43:38.867 回答
0

这应该可以解决问题:

$('ul.nav li a').click(function(e){
    e.preventDefault();
    $(this).parent().find('li.active').removeClass('active');
    $(this).addClass('active');
});
于 2013-02-09T12:42:21.070 回答
0

我认为您可能更容易使用为您执行此操作的 bootstrap buttonDropdown组件。

尝试将这些按钮下拉菜单与buttonGroups组件一起使用,以使您的按钮组合在一起并应用您的 css 使其看起来像您的菜单。

您不需要任何额外的 JavaScript 来使您的菜单正常工作!

于 2013-02-09T12:43:17.030 回答