当在静态页面中引用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>
问题解决了!坑爹的点啊。希望能帮到遇到相同问题的你