空格:$('parent childchild')表示獲取parent下的全部的childchild節點,全部的子孫。 html
大於號:$('parent > child')表示獲取parent下的全部child的兒子,第一代。 jquery
加號:$('pre + nextbrother')表示得到pre節點的下一個兄弟節點,至關於next()方法 app
波浪號:$('pre ~ brother')表示獲取pre節點的後面的全部兄弟節點,至關於nextAll()方法。 spa
下面是一個小例子,看看他們的區別吧~~~~ htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src='f:/study/jquery.js'></script>
<script>
$(function(){
$("#b").append($("#a span").clone());
$("#c").append($("#span12 + span").clone());
$("#d").append($("#span12 ~ span").clone());
$("#e").append($("#a > span").clone());
})
</script>
</head> ip
<body>
<div id='a'>
<span>span1</span>
<div>
<span>span1.1</span>
<span id='span12'>span1.2</span>
<span>span1.3</span> get
<span>span1.4</span>
<span>span1.5</span>
<span>span1.6</span>
</div>
<span>span2</span>
<div>
<span>span2.1</span>
<span>span2.2</span>
<span>span2.3</span>
<span>span2.4</span>
<span>span2.5</span>
<span>span2.6</span>
</div>
<span>span3</span>
<span>span4</span>
</div> it
<hr>
<div id='b'></div>
空格:
<hr>
<div id='c'></div>
+:
<hr>
<div id='d'></div>
~:
<hr>
<div id='e'>
>
</div>
</body>
</html> io