Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Thymeleaf调用th:if中的JavaScript方法?_Javascript_Html_Thymeleaf - Fatal编程技术网

如何从Thymeleaf调用th:if中的JavaScript方法?

如何从Thymeleaf调用th:if中的JavaScript方法?,javascript,html,thymeleaf,Javascript,Html,Thymeleaf,标题说明了一切。我有这样一个HTML元素: <label th:if="${#fields.hasErrors('weight') && 'isModalFirstOpening();'}" th:errors="*{weight}"></label> 您可以在这里看到,我只想在变量weight中出现错误时显示此标签字段,并且javascript函数isModalFirstoping()返回true。但是,此代码不起作用 你能帮我吗?感谢阅读。jav

标题说明了一切。我有这样一个HTML元素:

<label th:if="${#fields.hasErrors('weight') && 'isModalFirstOpening();'}" th:errors="*{weight}"></label>

您可以在这里看到,我只想在变量
weight
中出现错误时显示此标签字段,并且javascript函数
isModalFirstoping()
返回true。但是,此代码不起作用


你能帮我吗?感谢阅读。

javascripts在web浏览器上运行,thymeleaf在服务器端运行。是的,我知道。不过,仍然有一些方法可以让th:onclick与Javascript函数绑定。我正在寻找这样的解决方案。对不起,也许我不清楚。
th:if
在服务器端运行,而将在html元素上生成属性。一般来说,您所看到的是后端前端集成。我个人会使用隐藏字段方法,其中
isModalFirstoping()
不是js函数,而是检查所述隐藏字段值的java方法。