如何将 "th:src" thymeleaf 标签包含到 append() jquery 方法中?
How can I include "th:src" thymeleaf tag into an append() jquery method?
如何将 "th:src="@{'....'}"
包含到 append()
jquery 方法中?
我有这段代码,但 <img
> 标签不起作用。我不知道如何使用 th:src 变成 javascript.
代码:
<script th:inline="javascript">
/*<![CDATA[*/
var imagenes = /*[[${imagenes}]]*/ null;
console.log(imagenes);
$.each(imagenes, function(index, value){
if(index != 0) {
$("#carousel-inner").append(
"<div class='carousel-item'>" +
"<img /*[[th:src=@{'/imagenes_productos/}" + value + "']]*/ class='d-block w-100' />" +
"</div>"
);
}
});
/*]]>*/
</script>
代码图片:
code image
Thymeleaf 在服务器上呈现 Thymeleaf 模板并将其作为 HTML 发送到浏览器。进入浏览器后,您可以使用 JavaScript(和 jQuery)进一步操作页面,但此时 Thymeleaf 不再处于活动状态。因此,您不能使用 th:...
属性,因为浏览器中没有 Thymeleaf 引擎 运行 来解释这些属性。
您应该使用正常的 src
属性,而不是 th:src
。
如何将 "th:src="@{'....'}"
包含到 append()
jquery 方法中?
我有这段代码,但 <img
> 标签不起作用。我不知道如何使用 th:src 变成 javascript.
代码:
<script th:inline="javascript">
/*<![CDATA[*/
var imagenes = /*[[${imagenes}]]*/ null;
console.log(imagenes);
$.each(imagenes, function(index, value){
if(index != 0) {
$("#carousel-inner").append(
"<div class='carousel-item'>" +
"<img /*[[th:src=@{'/imagenes_productos/}" + value + "']]*/ class='d-block w-100' />" +
"</div>"
);
}
});
/*]]>*/
</script>
代码图片: code image
Thymeleaf 在服务器上呈现 Thymeleaf 模板并将其作为 HTML 发送到浏览器。进入浏览器后,您可以使用 JavaScript(和 jQuery)进一步操作页面,但此时 Thymeleaf 不再处于活动状态。因此,您不能使用 th:...
属性,因为浏览器中没有 Thymeleaf 引擎 运行 来解释这些属性。
您应该使用正常的 src
属性,而不是 th:src
。