我有一个使用 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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句