當前我在前端編程,並遇到一個問題,我的JavaScript文件不加載。我的文件是scala/scalatra後端的.jsp版本。我有我的index.jsp,其中我的頭文件包含在頂部和底部,包括我的頁腳。JavaScript文件未加載到.jsp文件中
我有他們這樣的:
<jsp:include page="header.jsp"/>
// CODE //
<jsp:include page="footer.jsp"/>
我的頭看起來是這樣的:
<!-- HEADER -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="styles/cssfile.css">
<link rel="stylesheet" href="css/cssfile.css">
</head>
<body>
我的頁腳是這樣的:
<!-- FOOTER -->
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
我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應該加載。
感謝提前:)
實際發送到瀏覽器的結果HTML是什麼?在瀏覽器的調試工具中,是否需要創建'.js'文件?服務器的迴應是什麼?在你的'.js'中是否有另一個錯誤阻止'console.log(「test」);'執行?顯示足夠的代碼來複制問題。 – David