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

發佈了1402 篇原創文章 · 獲贊 251 · 訪問量 36萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章