java - 根据 Thymeleaf 中的特定条件使图像可点击
问题描述
我正在获取一个属性 html“image_clickable_status”,如果它是 true,我需要使图像可点击,如果它是 false,则图像不应该是可点击的。下面是我想要做的
<div th:switch=${image_clickable_status}>
<a th:case=“true ” th:href="@{/getConsent/yes}">
<a th:case=“false ” th:href=“#”>
<img
src="https://samplegoogle.img" alt="viu"/>
</a>
</a>
</div>
但这不起作用,任何想法如何以更好的方式处理这种情况。
解决方案
您可能希望使用if-else
语句来区分链接和段落:
<div th:if="${image_clickable_status}">
<a th:case=“true ” th:href="@{/getConsent/yes}">
<img src="https://samplegoogle.img" alt="viu"/>
</a>
</div>
<div th:unless="${image_clickable_status}">
<img src="https://samplegoogle.img" alt="viu"/>
</div>
上面的解决方案有点冗长。或者,使用该样式使链接不可点击并默认使用光标指针。
<a th:style="${image_clickable_status} ? '' : " +
"'pointer-events: none; cursor: default;'"
th:href="@{/getConsent/yes}">
<img src="https://samplegoogle.img" alt="viu"/>
</a>
推荐阅读
- c# - 我的 C# 代码的结构和我的思维方式是否正确?
- javascript - Javascript:如何调用数组数组中的不同对象?
- android - android.support.constraint.ConstraintLayout 不能转换为 android.widget.EditText
- javascript - 在背景音乐中添加两秒延迟
- r - 在R中将aplucter的结果绑定到数据帧
- java - 以编程方式确定 Java 类是否被修补?
- php - 如何更改 Crinsane/LaravelShoppingcart 中的默认货币?
- c# - 我收到一个错误。“Where”和“Take”值未出现在列表数据中
- c# - 使用测试工具,需要编写一个函数,使测试用例通过 IndexOf 一个字符串和一个字符
- bdd - 如果前面的步骤在 Jbehave 中失败,如何停止执行后面的步骤