简体   繁体   English

如何使用 Thymeleaf th:if 调用 javascript function 没有 ZC0BB2196426022E8AEDF9A5B?

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

I am building Login page with Spring boot and thymeleaf.我正在使用 Spring 引导和 thymeleaf 构建登录页面。 I pass the opcode using model attribute.我使用 model 属性传递操作码。 And I want to use it for th:if to make condition to call javascript function automatically(meaning: without any click).我想将它用于 th:if 以自动调用 javascript function (意思是:无需任何点击)。 Here is my code under.这是我的代码。

<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>

Put the th:if on the script itself.th:if放在脚本本身上。 For example:例如:

<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.

相关问题 如何使用onclick HTML属性调用JavaScript中的函数? - How can I use an onclick HTML attribute to call a function in JavaScript? thymeleaf th:onclick没有看到javascript函数 - thymeleaf th:onclick doesn't see javascript function 如何从 html onclick 中的 javascript 模块调用函数 - How can I call a function from javascript module in html onclick 如何使用 thymeleaf 属性 th:href 调用 java 脚本函数? - How to call java script function using thymeleaf attribute th:href? th:onclick with javascript 函数调用一直说该函数未声明 - th:onclick with javascript function call keeps saying the function is not declared 如何使用 thymeleaf onclick 在单个 Javascript 方法中传递多个 arguments - How to pass multiple arguments in a single Javascript method using thymeleaf onclick (th:onclick) 将 JavaScript 文字传递给 th 时,Thymeleaf 找不到我的变量:onclick - Thymeleaf can't find my variable when passing JavaScript literal to th:onclick 在百里香中调用javascript函数 - Call javascript function in thymeleaf 如何在onClick函数中编写JavaScript代码以及我也想调用另一个函数 - How can I write JavaScript code in onClick function as well as I also want to call another function Thymeleaf:在Javascript中使用带有&#39;th:href&#39;的链接 - Thymeleaf: Use a link with 'th:href' in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM