當在靜態頁面中引用jquery相當簡單,只需要在head內加上<script src="jquery路徑">就可以了。但是在web工程中使用上面的方法就發現找不到jquery。當時鬱悶了很久,上網也找了很多依然沒有解決。後來我想到要在路徑前加點,於是我非常任性的在前面加了兩個點。但是並沒有什麼卵用。
下面給個簡單的例子。並不具備任何意義
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
function fun(){
alert("In....");
alert($("#tb"));
alert($("#text").val());
}
</script>
</head>
<body>
<form action="">
<table id="tb">
<tr><td><input type="text" id="text" value="123"></td></tr>
<tr><td><input type="button" value="Click" onclick="fun()">
</table>
</form>
</body>
</html>
ok,按道理說應該是沒問題的,但是在我的myeclipse中就是找不到jquery。
於是,我在路徑前加了兩個點
<script type="text/javascript" src="../jquery-1.4.1.min.js"></script>
並沒有什麼卵用!!!!
後來,媽的只加一個點!!!!
<script type="text/javascript" src="./jquery-1.4.1.min.js"></script>
問題解決了!坑爹的點啊。希望能幫到遇到相同問題的你