如何禁用定义的th:href链接:值
我是Java Spring Development的新手。 有一个用于生成活动“ href-links”的百里角代码:
<td> <a id="requeststatus"
th:each="requeststatus : ${requeststatuses}"
th:if="(${requeststatus.id} == ${request.request_status_id})"
th:href="@{'/system/request/edit/requeststatusid/' + ${request.id}}"
th:text="${requeststatus.title}" th:value="${requeststatus.id}"
th:unless="${requeststatus.id} >= 4" >
</a>
</td>
for th:除非=“ $ {requestStatus.id}&gt; = 4“我得到空了$ {requestStatus.title},但是我需要获取不单击的request requestStatus。代替$ {requestStatus.id}&gt; = 4
。
I'm a new in Java Spring Development.
There is a Thymeleaf code for generating active "href-links":
<td> <a id="requeststatus"
th:each="requeststatus : ${requeststatuses}"
th:if="(${requeststatus.id} == ${request.request_status_id})"
th:href="@{'/system/request/edit/requeststatusid/' + ${request.id}}"
th:text="${requeststatus.title}" th:value="${requeststatus.id}"
th:unless="${requeststatus.id} >= 4" >
</a>
</td>
For th:unless="${requeststatus.id} >= 4" i get empty ${requeststatus.title}, but i need get just not clickable requeststatus.title instead href for ${requeststatus.id} >= 4.
For example, how do I make a link inactive for ${requeststatus.id} >= 4 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如@andrewjames在有条件禁用链接的评论中所述,这不是一个好习惯。使用
Th:Switch
您可以用相同的文本替换a
,例如span
。通常,如果您想要不同的行为,具体取决于变量,最好将所述行为包裹在
th:block
的情况下,使用适当的(如果
> 或switch> switch> switch case
)条件PS:在HTML中,
id
应该是唯一的,因此,不应完成for loop中的静态ID,例如,您可以将iTer部分添加到for for for for for loop并制作诸如requestStatus1 ,
.. 2
,等等。As stated in comments by @andrewJames conditionally disabling the link is not good practice. using
th:switch
you can replace thea
with, for example aspan
with the same text.In general if you want different behaviour depending on a variable it's best to wrap said behaviour in a
th:block
with an appropriateif
orswitch case
conditionPS: in html the
id
should be unique, as such using a static id in a for loop should not be done, you could for example add the iter part to for loop and make ids likerequeststatus1
,..2
, etc.在CSS的帮助下,您可以禁用超链接。尝试以下
或与JS
希望这有帮助:)
With the help of CSS you can disable the hyperlink. Try the below
Or with the JS
Hope this helps :)