Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.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中使用onClick时如何将参数传递给javascript函数调用_Java_Spring Boot_Thymeleaf - Fatal编程技术网

在Thymeleaf中使用onClick时如何将参数传递给javascript函数调用

在Thymeleaf中使用onClick时如何将参数传递给javascript函数调用,java,spring-boot,thymeleaf,Java,Spring Boot,Thymeleaf,我一直在从ThymileAF调用javascript函数,如下所示: th:onclick="'viewDocument(\'' + ${document.docTypeLongDesc} +'\');'" 但我刚刚将我的spring boot版本更新为2.1.4版本,Thymeleaf也随之更新。不再支持中的早期版本 在进一步的研究中,我发现我应该能够使用 th:onclick="' viewDocument (this.getAttribute ('document.docTypeLong

我一直在从ThymileAF调用javascript函数,如下所示:

th:onclick="'viewDocument(\'' + ${document.docTypeLongDesc} +'\');'"
但我刚刚将我的spring boot版本更新为2.1.4版本,Thymeleaf也随之更新。不再支持中的早期版本

在进一步的研究中,我发现我应该能够使用

th:onclick="' viewDocument (this.getAttribute ('document.docTypeLongDesc'));'"

但是,它没有给出任何错误,但也不起作用。我已经删除了参数,并且能够很好地调用函数。所以我猜我没有正确地传递论点。任何指导都会有帮助。TIA.

您应该按如下方式使用它:

th:onclick="${'viewDocument(' + document.docTypeLongDesc + ');'}"
请参见:

为了正确地向onclick事件传递Thymeleaf变量,请将变量放入
data
属性中,并使用
getAttribute()
读取它


我引用了相同的链接并以相同的方式使用它,但仍然得到运行时错误:org.thymeleaf.exceptions.TemplateInputException:在模板解析过程中发生错误(模板:“template/th_documentsDetails.html”)。Intellij还将this.getAttribute高亮显示为红色,高亮显示时表示无法识别。我想这很可能是某个地方的语法错误。@ILRNew您是否注意到我不再使用
th:onclick
,现在它只是一个常规的
onclick
,因为它不再需要是一个thymeleaf表达式。您实际上是对的。我没注意到。一旦我这么做了,它就像一个符咒。非常感谢你。我可以问你如何更多地了解新百里香吗?
th:data-longDescription="${document.docTypeLongDesc}" onclick="viewDocument(this.getAttribute('data-longDescription'));"