admin管理员组

文章数量:1331849

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:

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.

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:

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.

Share Improve this question asked Aug 16, 2014 at 22:48 Ronnie147Ronnie147 393 silver badges8 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 8

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'. Then try to acess it via your browser. Normaly it should display the image.

本文标签: javascriptthymeleaf js source urlStack Overflow