JQuery学习(层级)ancestor & descendant

时间:2024-11-03 08:37:20
 <%@ 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>
<base href="<%=basePath%>"> <title>My JSP 'jquery.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">
<script type="text/javascript" src="/common/easyui/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("form input").css("background-color","yellow");
}); </script> </head>
<body>
<form>
<label>Name:</label>
<input name="name" />
<fieldset>
<label>Newsletter:</label>
<input name="newsletter" />
</fieldset>
</form>
<input name="none" /> </body>
</html>

JQuery学习(层级)ancestor & descendant

            效果图1-1

重点解释:

 $("form input"):即form下所有input
结合JQuery1.4.2API还有: parent>children:父元素下所有子元素
$("form > input"):form下所有input prev+next:跟在prev后所有的next元素
$("form+input"):跟在form后的所有input元素 prev ~ siblings:与prev同级的siblings元素
$("form ~ input"):与form同级的input元素