简体   繁体   English

百里香js源url

[英]thymeleaf js source url

I'm trying to develop a web application with Thymeleaf and I've created an html page that uses an external JavaScript file to change an image URL.But the standard syntax URL: 我正在尝试使用Thymeleaf开发Web应用程序,并且创建了一个html页面,该页面使用外部JavaScript文件来更改图像URL。但是标准语法URL:

document.getElementById("im1").src="images/img1.jpg" ;

does not work.Everything else in the JavaScript code works fine.What kind of URL syntax should I use?Thanks in advance. 不起作用,JavaScript代码中的其他所有内容都可以正常工作,我应该使用哪种URL语法?

Try something like : 尝试类似的东西:

<script th:inline="javascript">
    /*<![CDATA[*/
        var context = [[@{/}]];
    /*]]>*/

    document.getElementById("im1").src=context + 'images/img1.jpg' ;

</script>

Maybe your code didn't reach the image in the context. 也许您的代码没有到达上下文中的图像。 Debug or use console to see the URL generated from: context + 'images/img1.jpg'. 调试或使用控制台查看从以下位置生成的URL:context +'images / img1.jpg'。 Then try to acess it via your browser. 然后尝试通过浏览器访问它。 Normaly it should display the image. 通常它应该显示图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM