jQuery 的简单例子.

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>
		<script type="text/javascript"
			src="/jQuery/jQuery/jquery-1.2.6.pack.js"></script>
		
		<script type="text/javascript">
			function clickDiv(){
    			alert($(document).find("div>div").attr("id"));
    		}
    		
    		function setUL(){
    			$("ul li:eq(0)").attr({style:'color:red'});
    	     	$("ul li:eq(1)").attr({style:"color:blue",id:"liid",alt:"altId",title:"香蕉"});
    			$("ul li:eq(2)").attr({style:'color:yellow'});
    			
    			//显示第二个li标记中id的属性值;
    			alert($("ul li:eq(1)").attr("id"));
    			//显示第二个li标记中title的属性值;
    			alert($("ul li:eq(1)").attr("title"));
    			//移除第二个li标签中的属性值;
    			$("ul li:eq(1)").removeAttr("title");
    		}
		</script>
  </head>
  
  <body>
    <div id='a1' onclick="clickDiv()">
    		<div id='b1'>测试</div>
	</div>
	
	<br>
	<ul onclick="setUL()">
		<li>小苹果</li>
		<li>小香蕉</li>
		<li>小荔枝</li>
	</ul>
  </body>
</html>

 

你可能感兴趣的:(JavaScript,html,jquery)