jQuery选择器的分类:
------基本选择器(basic)
------层次选择器(level)
------过滤选择器(filter)
------表单选择器(form)
基本选择器
实例1:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.8.1.js">
</script>
<script type="text/javascript">
$(function(){
alert("id--->"+$("#test").length);
alert("class--->"+$(".test").length);
});
</script>
</head>
<body>
<a id="test">test1</a>
<a id="test">test1</a>
<a class="test">test2</a>
<a class="test">test2</a>
</body>
</html>
结果:id---->1 class---->2
层次选择器:
实例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.8.1.js">
</script>
<script type="text/javascript">
$(function(){
alert($("body div").length);
alert($("body > div").length);
alert($("a + p").length);
alert($("a ~ p").length);
});
</script>
</head>
<body>
<div>
<font>
<div>这个div无法通过body > div得到</div>
</font>
</div>
<div>
<font>aaa</font>
</div>
<div>
<font>bbb</font>
</div>
<a class="one"></a>
<p></p>
<p>a + p无法选择到这个</p>
<p>a + p无法选择到这个</p>
</body>
</html>
运行结果:
body div ---->4
body > div ---->3
a + p ---->1
a ~ p ----->3
过滤选择器
----基本过滤
----内容过滤
----可见性过滤
----属性过滤
----子元素过滤
-----表单对象属性过滤
基本过滤
内容过滤
可见性过滤器
实例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.8.1.js">
</script>
<script type="text/javascript">
$(function(){
$("#click").click(function(){
$(":hidden").show(1000).css("background","blue");
});
});
</script>
</head>
<body>
<input type="button" value="出来吧" id="click">
<div style="width:400px;height:400px;border:solid;display:none">
看我慢慢的出来啦。。。
</div>
</body>
</html>
属性过滤
子元素过滤
表单对象属性过滤
表单元素过滤器