SpringBoot----thymeleaf的点击后改变样式32

侧边栏希望能做到点击之后改变颜色或者样式,让用户知道自己所在的目录

这里只是简单的例子,具体可以查看usingthymeleaf的pdf文档

第一步:给引入的侧边栏传入固定的参数,当打开这个页面的时候固定的向侧边栏传入参数

<div th:replace="~{commons/bar :: #sidebar(activeUri='emps')}"></div>

这里向id为sidebar的片段传入activeUri。可以通过逗号分隔来添加多个变量名


第二步:在侧边栏的片段部分的class标签做判断

<li class="nav-item">
                <a
                   th:class="${activeUri=='main.html'?'nav-link active':'nav-link'}"
                   th:href="@{/main.html}">
                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home">
                        <path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>
                        <polyline points="9 22 9 12 15 12 15 22"></polyline>
                    </svg>
                    Dashboard <span class="sr-only">(current)</span>
                </a>
            </li>

这里用来(?a:b)三元表达式做判断,通过参数选择样式

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值