JavaScript文件没有';t载荷
我正在使用SpringMVC、Thymeleaf,并希望在我的html文档中导入一个javascript文件。虽然所有链接都已正确设置,并且文件显示在“我的浏览器”的“调试”视图中,但它们不会加载。 HTML中有以下JS应该调用日期选择器,但它没有显示:JavaScript文件没有';t载荷,javascript,jquery,html,spring-mvc,thymeleaf,Javascript,Jquery,Html,Spring Mvc,Thymeleaf,我正在使用SpringMVC、Thymeleaf,并希望在我的html文档中导入一个javascript文件。虽然所有链接都已正确设置,并且文件显示在“我的浏览器”的“调试”视图中,但它们不会加载。 HTML中有以下JS应该调用日期选择器,但它没有显示: <script th:inline="javascript"> /*<![CDATA[*/ $( function() { $( "#datepicker" ).Datepicker( ); } )
<script th:inline="javascript">
/*<![CDATA[*/
$( function() {
$( "#datepicker" ).Datepicker(
);
} );
/*]]>*/
</script>
/**/
这些文件是通过以下方式包含的:
<script type="text/javascript" th:src="@{/resources/js/file.js}"></script>
CSS文件只需更改类型即可正常工作
有没有办法解决这个问题
现在我从导入中删除了所有不必要的js文件,并显示以下错误:
这表明使用了jquery-1.12.4 答案是:
1)
没有区别
2) 添加到html标记的内容
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
没什么区别
3) 将内容放在正文底部的脚本标记与将其放在头部时相同
4) 我在这个项目中使用Bootstrap,并在Bootstrap的div中使用了日期选择器。在把它放在身体的其他地方,而不是在一个div里面之后,它就开始工作了
结论:
如果您正在使用Spring MVC和Thymeleaf,并且希望包含所需的JavaScript文件:
1)
2)
3)
4) 确保您的JS或CSS文件不会被以下文件“覆盖”
感谢您的时间和帮助@Parth 答案是:
1)
没有区别
2) 添加到html标记的内容
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
没什么区别
3) 将内容放在正文底部的脚本标记与将其放在头部时相同
4) 我在这个项目中使用Bootstrap,并在Bootstrap的div中使用了日期选择器。在把它放在身体的其他地方,而不是在一个div里面之后,它就开始工作了
结论:
如果您正在使用Spring MVC和Thymeleaf,并且希望包含所需的JavaScript文件:
1)
2)
3)
4) 确保您的JS或CSS文件不会被以下文件“覆盖”
感谢您的时间和帮助@Parth 使用Spring和Thymeleaf时,建议使用以下项目结构:
src
|-main
|-resources
|-static
| |-css
| |-bootstrap.min.css
| |-application.css
| |-images
| |-js
| |-jquery-3.1.1.js
|-templates
然后,在模板中包含不同的资源将如下所示:
<head>
<link href="../static/css/bootstrap.min.css" rel="stylesheet" media="screen"
th:href="@{/css/bootstrap.css}"/>
<link href="../static/css/application.css" rel="stylesheet" media="screen"
th:href="@{/css/application.css}"/>
<script src="../static/js/jquery-3.1.1.js"
th:src="@{/js/jquery-3.1.1.js}"></script>
</head>
使用Spring和Thymeleaf时,建议使用以下项目结构:
src
|-main
|-resources
|-static
| |-css
| |-bootstrap.min.css
| |-application.css
| |-images
| |-js
| |-jquery-3.1.1.js
|-templates
然后,在模板中包含不同的资源将如下所示:
<head>
<link href="../static/css/bootstrap.min.css" rel="stylesheet" media="screen"
th:href="@{/css/bootstrap.css}"/>
<link href="../static/css/application.css" rel="stylesheet" media="screen"
th:href="@{/css/application.css}"/>
<script src="../static/js/jquery-3.1.1.js"
th:src="@{/js/jquery-3.1.1.js}"></script>
</head>