[英]<script> tag works in HTML file but not external .js file
[英]jQuery script works when in HTML but not in external file
我有一個使用jQuery的測試,在html文件中工作正常,但是當我將其放入外部js文件中時,它不起作用,請幫助,我需要它來繼續我的應用程序。 query.js在/ js目錄中
HTML:detail.jsp
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="springform" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8">
<title>Ajouter annonce</title>
<link type="text/css" href="/bootstrap/dist/css/bootstrap.css" rel="stylesheet" >
<link type="text/css" href="/css/style.css" rel="stylesheet" >
<script src="https://code.jquery.com/jquery-2.1.1.js"></script>
<script type="text/javascript" src="js/query.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</head>
<body class="body2">
<div id="test" class="test" > Allo</div>
</body>
</html>
js文件:query.js
$(document).ready(function(){
$("#test").click(function(){
alert("hello");
})
});
在評論的幫助下,我發現錯誤出在路徑中:
<script type="text/javascript" src="/js/query.js"></script>
代替 :
<script type="text/javascript" src="js/query.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.