如何更改导航栏中选定项目的类属性 [英] how to change the class attribute of a selected item in the navigation bar

查看:148
本文介绍了如何更改导航栏中选定项目的类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < div class =nav

我使用的是twitter bootstrap和grails, -collapse>
< ul class =nav>
< li>< a href =$ {createLink(uri:'/ request / new')}>我的链接< / a>< / li>
< / ul>
< / div>

在我的页面上,我有以下内容:

 < HTML> 
< head>
< meta name =layoutcontent =bootstrap>
< / head>

< body>
sometext
< / body>
< / html>

问题

在我的布局中,如何检测何时点击 My Link 动作?所以我可以使用 class =active

解决方案

首先,在你的布局中,你可以做这样的事情:




pre> < div class =nav-collapse>
< ul class =nav>
< li class =$ {pageProperty(name:'meta.nav')。equals('foo')?'active':null}>< a href =$ {createLink(uri :'/ request / new')}>我的链接< / a>< / li>
< / ul>
< / div>

并在您的页面中:

 < HTML> 
< head>
< meta name =layoutcontent =bootstrap>
< meta name =navcontent =foo/>
< / head>

< body>
sometext
< / body>
< / html>

foo 是应用 .active class。


I'm using twitter bootstrap with grails and have the following in my layout:

        <div class="nav-collapse">
            <ul class="nav">
                <li><a href="${createLink(uri: '/request/new')}">My Link</a></li>
            </ul>
        </div>

On my page I have the following:

<html>
    <head>
        <meta name="layout" content="bootstrap">
    </head>

    <body>
        sometext
    </body>
</html>

Question

In my layout how do I detect when the My Link action is clicked? so that I can highlight it using class="active"

解决方案

Here is how I tend to do this.

First, in your layout, you would do something like this:

<div class="nav-collapse">
    <ul class="nav">
        <li class="${ pageProperty(name:'meta.nav').equals( 'foo' ) ? 'active' : null }"><a href="${createLink(uri: '/request/new')}">My Link</a></li>
    </ul>
</div>

And in your page:

<html>
    <head>
        <meta name="layout" content="bootstrap">
        <meta name="nav" content="foo"/>
    </head>

    <body>
        sometext
    </body>
</html>

foo is the trigger to apply the .active class.

这篇关于如何更改导航栏中选定项目的类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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