Thymeleaf——在不覆盖现有class属性的情况下动态添加CSS class解决方案

问题描述

th:class动态添加CSS class覆盖现有class属性,导致class较多时,表达式过长。

官方文档

https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#appending-and-prepending

解决方案

th:classappend:用于在不覆盖现有属性的情况下向元素添加CSS class。 

<tr th:each="prod : ${prods}" class="row" th:classappend="${prodStat.odd}? 'odd'">

扩展

参考文章

https://blog.csdn.net/weixin_44357646/article/details/100837365

发布了1371 篇原创文章 · 获赞 237 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/weixin_43272781/article/details/104155520