Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.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
Javascript Thymeleaf:将文本与变量组合_Javascript_Html_Spring Boot_Thymeleaf - Fatal编程技术网

Javascript Thymeleaf:将文本与变量组合

Javascript Thymeleaf:将文本与变量组合,javascript,html,spring-boot,thymeleaf,Javascript,Html,Spring Boot,Thymeleaf,我在Thymeleaf中有一段代码: <tr th:each="image: ${images}" > <img th:onmouseover="'javascript:imageName(\'theImageName\' + ${image.id} +'\');'"> </tr> 但是我遇到了一个解析错误你能试试下面的方法吗 <img th:onmouseover="'javascript:imageName(\''+ theImage

我在Thymeleaf中有一段代码:

<tr th:each="image: ${images}" >
    <img th:onmouseover="'javascript:imageName(\'theImageName\' + ${image.id} +'\');'"> 
</tr>


但是我遇到了一个解析错误

你能试试下面的方法吗

<img th:onmouseover="'javascript:imageName(\''+ theImageName\' + ${image.id} +'\');'"> 

您可以尝试以下方法吗

<img th:onmouseover="'javascript:imageName(\''+ theImageName\' + ${image.id} +'\');'"> 

我将其格式化如下:

<tr th:each="image: ${images}" >
    <img th:onmouseover="${'javascript:imageName(''theImageName' + image.id + ''');'}"> 
</tr>

我将其格式化如下:

<tr th:each="image: ${images}" >
    <img th:onmouseover="${'javascript:imageName(''theImageName' + image.id + ''');'}"> 
</tr>

您能试试下面的代码吗

<img th:attr="onmouseover=${'javascript:imageName(''theImageName' + image.id + ''');'}">


这个答案的灵感来源于Thymeleaf文档的相关部分。

您能试试下面的代码吗

<img th:attr="onmouseover=${'javascript:imageName(''theImageName' + image.id + ''');'}">


这个答案的灵感来源于Thymeleaf文档的相关部分。

我有两个观察结果:

打开标签?

某些Thymeleaf模板模式要求模板格式良好。如果是这种情况,任何未关闭的
img
标记都将导致解析错误

发生这种情况时,java堆栈跟踪提供信息:

org.xml.sax.SAXParseException: The element type "img" must be terminated by the matching end-tag "</img>".
我的最低配置Spring Boot应用程序默认为这些更严格的模式之一(
HTML5
XML
),因此@Metroid'和@ErikMD的答案都会给我一个解析错误,但如果我关闭图像标记,这两种方法都会起作用

如果您不是这样,那么使用java堆栈跟踪更新问题可能会有所帮助

管道

我认为所有这些撇号和加号使得标记很难读(和写)。可以说,使用更清晰(且不易出错):


我有两个意见:

打开标签?

某些Thymeleaf模板模式要求模板格式良好。如果是这种情况,任何未关闭的
img
标记都将导致解析错误

发生这种情况时,java堆栈跟踪提供信息:

org.xml.sax.SAXParseException: The element type "img" must be terminated by the matching end-tag "</img>".
我的最低配置Spring Boot应用程序默认为这些更严格的模式之一(
HTML5
XML
),因此@Metroid'和@ErikMD的答案都会给我一个解析错误,但如果我关闭图像标记,这两种方法都会起作用

如果您不是这样,那么使用java堆栈跟踪更新问题可能会有所帮助

管道

我认为所有这些撇号和加号使得标记很难读(和写)。可以说,使用更清晰(且不易出错):


@请你现在试一试好吗?我已经更新了我的回答相同的结果:-(@enLopes你能现在试试吗?我已经更新了我的回答相同的结果:-(@enLopes我用变量测试了这个…如果你仍然有解析错误,其他的事情正在发生。@enLopes我用变量测试了这个…如果你仍然有解析错误,其他的事情正在发生。