Twitter的引导+ asp.net masterpages,当用户选择它如何设置导航栏项目为活动? [英] Twitter bootstrap + asp.net masterpages, how to set navbar item as active when user selects it?

查看:131
本文介绍了Twitter的引导+ asp.net masterpages,当用户选择它如何设置导航栏项目为活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在本质上一样的情况的问题让Twitter的引导导航栏链接活跃,但在我们的例子中,我们使用的是ASP.net和MasterPages ...

We are in se same situation as question Make Twitter Bootstrap navbar link active, but in our case we are using ASP.net and MasterPages...

的东西是导航栏是在母版定义,当你点击你将被重定向到相应的子页面菜单项,所以你会怎么做才能改变consecuently导航栏活动项目无需在每个子页复制逻辑? (preferably无会话变量和JavaScript只在母版页)

The thing is the navbar is defined at the masterpage and when you click a menuitem you are redirected to the corresponding child page so how would you do to change the navbar active item consecuently without replicating the logic in each child page? (Preferably without session variables and javascript only at master page)

推荐答案

我们与母版页下面的函数解决它:

We solved it with the following function at Master Page:

 <script type="text/javascript">
        $(document).ready(function () {
            var url = window.location.pathname;
            var substr = url.split('/');
            var urlaspx = substr[substr.length-1];
            $('.nav').find('.active').removeClass('active');
            $('.nav li a').each(function () {
                if (this.href.indexOf(urlaspx) >= 0) {
                    $(this).parent().addClass('active');
                }
            });
        });
    </script>

这篇关于Twitter的引导+ asp.net masterpages,当用户选择它如何设置导航栏项目为活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆