[英]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.