html - Thymeleaf:是否有类似于 th:classappend 的东西来删除类值?

标签 html thymeleaf

我正在尝试使用以下代码在某个屏幕上显示一个警报:

<div id="errorDiv" class="alert alert-danger hidden">
    <label id="errorLabel"></label>
    <button type="button" class="close" data-hide="alert" aria-hidden="true">&times;</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">&times;</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/

相关文章:

javascript - 一种3d旋转效果,只用css3、html5和javascript可以吗?

java - 如何使用 thymeleaf 和 spring 国际化动态更改语言选择链接

html - 使用 CSS,如何控制主标题的行高?

javascript - 在 Javascript 中动态设置 CSS 背景

spring-mvc - 在 Thymeleaf 方言处理器中访问 HttpServletRequest 和 HttpServletResponse

java - 我可以在没有粘性 session 的情况下使用 Thymeleaf 模板 + 绑定(bind)吗?

java - Spring Boot、Thymeleaf 组合类验证

java - 无法在特定端点使用 thymeleaf 访问静态资源

Html文件到Aspose幻灯片的转换

html - 防止带有进度条的 Flexbox 增长