如何禁用定义的th:href链接:值

发布于 2025-02-11 17:22:18 字数 673 浏览 1 评论 0原文

我是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑾兮 2025-02-18 17:22:18

正如@andrewjames在有条件禁用链接的评论中所述,这不是一个好习惯。使用Th:Switch您可以用相同的文本替换a,例如span
通常,如果您想要不同的行为,具体取决于变量,最好将所述行为包裹在th:block的情况下,使用适当的(如果> 或switch> switch> switch case)条件

<td> 
    <th:block th:each="requeststatus : ${requeststatuses}">
        <th:block th:switch="true">
            <a th:case="${requeststatus.id} < 4"
                id="requeststatus"
                th:href="@{'/system/request/edit/requeststatusid/' + ${request.id}}" 
                th:text="${requeststatus.title}" th:value="${requeststatus.id}" >                             
            </a>
            <span th:case="*" th:text="${requeststatus.title}"></span>
        </th:block>
    </th:block> 
 </td>

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 the a with, for example a span 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 appropriate if or switch case condition

<td> 
    <th:block th:each="requeststatus : ${requeststatuses}">
        <th:block th:switch="true">
            <a th:case="${requeststatus.id} < 4"
                id="requeststatus"
                th:href="@{'/system/request/edit/requeststatusid/' + ${request.id}}" 
                th:text="${requeststatus.title}" th:value="${requeststatus.id}" >                             
            </a>
            <span th:case="*" th:text="${requeststatus.title}"></span>
        </th:block>
    </th:block> 
 </td>

PS: 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 like requeststatus1 ,..2, etc.

怎樣才叫好 2025-02-18 17:22:18

在CSS的帮助下,您可以禁用超链接。尝试以下

a.disabled {
  pointer-events: none;
  cursor: default;
}
<a href="link.html" class="disabled">Link</a>

或与JS

<a href="javascript:function() { return false; }">link</a>
<a href="/" onclick="return false;">link</a>

/* You can also try void(0)

<a href="javascript:void(0)" style="cursor: default;">123n</a>

希望这有帮助:)

With the help of CSS you can disable the hyperlink. Try the below

a.disabled {
  pointer-events: none;
  cursor: default;
}
<a href="link.html" class="disabled">Link</a>

Or with the JS

<a href="javascript:function() { return false; }">link</a>
<a href="/" onclick="return false;">link</a>

/* You can also try void(0)

<a href="javascript:void(0)" style="cursor: default;">123n</a>

Hope this helps :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文