You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
比如
当状态为1时,class是 container green
状态为2时且状态为3时, class 是container red
状态为4时,class 为container blue
以前用的是jsp页面,在class属性中 c:if就可以,但是使用thymeleaf模板之后,无法实现这个效果.求大神,
The text was updated successfully, but these errors were encountered:
Hi there, unfortunately I don't speak Chinese, so am going to attempt an answer through Google Translate - I hope this works!
It seems like you're asking about applying a class to an element in Thymeleaf based on the value of some status. With JSPs you could use c:if to do that. In Thymeleaf, one way you can do this is using a variable expressions inside the th:class attribute processor.
Example:
<divth:class="${status == 1 ? 'green' : status == 2 || status == 3 ? 'red' : status == 4 ? 'blue' : ''}">
So if status was 1 you'd end up with <div class="green">, if it's 2 or 3 then <div class="red">, or if it's 4 then <div class="blue">.
Expressions are pretty powerful, so learning to use them will help you out. The expression syntax used depends on whether you're using Spring or not, but they're very similar:
比如
当状态为1时,class是 container green
状态为2时且状态为3时, class 是container red
状态为4时,class 为container blue
以前用的是jsp页面,在class属性中 c:if就可以,但是使用thymeleaf模板之后,无法实现这个效果.求大神,
The text was updated successfully, but these errors were encountered: