如何在jsp中添加 js库(和html中略有不同)(例程功能:按按钮改变label值)

<title>Index Page</title>
  <script type='text/javascript' src="${pageContext.request.contextPath}/jquery.js"></script>
  <!--
  <script type='text/javascript' src='/dwr/engine.js'></script>
  <script type='text/javascript' src='/dwr/interface/helloworldService.js'></script>
  <script type='text/javascript' src='/dwr/util.js'></script>
  -->
</head>

【注意:多个库时jquery.js库放到最前面】
p a g e C o n t e x t . r e q u e s t . c o n t e x t P a t h s r c = " {pageContext.request.contextPath}是自动定位到当前工程的目录】 **src=" {pageContext.request.contextPath}/jquery.js"**
对应的文件结构位置(jquery.js)在这里插入图片描述
web10.jsp测试文件源码:



<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!doctype html>
<html>
<head></head>
<body>
<label id="label1" >this is label1</label>
<input type="button" id="button1" value="button1">

<script src="${pageContext.request.contextPath}/jquery.js"></script>

<script>
$(document).ready(   function(){
						$("#button1").click(  function(){
								$("#label1").html("hello");
							}
						);
					}
				 );
</script>
</body>
</html>

【注:$是jquery.js库中的一个函数名】

猜你喜欢

转载自blog.csdn.net/jzlStudent/article/details/104445699