簡體   English   中英

如何使用 Thymeleaf th:if 調用 javascript function 沒有 ZC0BB2196426022E8AEDF9A5B?

[英]How can I use Thymeleaf th:if to call javascript function without onclick?

我正在使用 Spring 引導和 thymeleaf 構建登錄頁面。 我使用 model 屬性傳遞操作碼。 我想將它用於 th:if 以自動調用 javascript function (意思是:無需任何點擊)。 這是我的代碼。

<a th:if="${opcode == 1}" th:href="'javascript:setlocation()'"></a>

<script>
    function setlocation(){
        var msg = alert('Loss of location information found. Turning into setting page...');
        location.href='/setlocation';
    }
</script>

th:if放在腳本本身上。 例如:

<script th:if="${opcode == 1}">
    alert('Loss of location information found. Turning into setting page...');
    location.href='/setlocation';
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM