我正在尝试使用以下代码在某个屏幕上显示一个警报:
<div id="errorDiv" class="alert alert-danger hidden">
<label id="errorLabel"></label>
<button type="button" class="close" data-hide="alert" aria-hidden="true">×</button>
</div>
默认情况下,errorDiv div 是隐藏的,因为它的值隐藏在类属性中(我使用的是 Bootstrap )。
我想在Thymeleaf中找到类似于 th:classappend 的东西但不是添加值,而是删除类属性中的“隐藏”值以显示 div。
最佳答案
我认为您可以使用条件 css 类包含 elvis 运算符,例如:
<div id="errorDiv" class="alert alert-danger" th:classappend="*{isError}?:'hidden'">
<label id="errorLabel"></label>
<button type="button" class="close" data-hide="alert" aria-hidden="true">×</button>
</div>
仅当 *{isError}
为 null
时,才应将 'hidden'
附加到类属性。
参见 http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#default-expressions-elvis-operator
关于html - Thymeleaf:是否有类似于 th:classappend 的东西来删除类值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36740750/