当前我在前端编程,并遇到一个问题,我的JavaScript文件不加载。我的文件是scala/scalatra后端的.jsp版本。我有我的index.jsp,其中我的头文件包含在顶部和底部,包括我的页脚。JavaScript文件未加载到.jsp文件中
我有他们这样的:
// CODE //
我的头看起来是这样的:
我的页脚是这样的:
我main.js样子这个:
$(document).ready(function() {
'use strict';
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (
location.pathname.replace(/^//,'') == this.pathname.replace(/^//,'')
|| location.hostname == this.hostname
) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
});
我的文件结构是这样的:
css
-cssfile1
-cssfile2
js
-jquery.js
-main.js
header.jsp
index.jsp
footer.jsp
先生SRC路线shoulde是正确的,当我insepect网站的源代码,我可以看到main.js文件,并点击它,它是正确的js。 我试过console.log(“test”);并没有显示,所以它不会加载。 我添加了jquery.js并在其中添加了jquery javascript,并在页脚中添加了它,正如你所看到的。
所以我想要的是我的main.js应该加载。
感谢提前:)
2017-03-29
code4fun
+0
实际发送到浏览器的结果HTML是什么?在浏览器的调试工具中,是否需要创建'.js'文件?服务器的回应是什么?在你的'.js'中是否有另一个错误阻止'console.log(“test”);'执行?显示足够的代码来复制问题。 –