首頁  >  文章  >  web前端  >  簡述jquery中next、nextAll、nextUntil、siblings的差異與聯繫

簡述jquery中next、nextAll、nextUntil、siblings的差異與聯繫

巴扎黑
巴扎黑原創
2017-06-22 14:07:181525瀏覽

在本文為大家詳細介紹下jquery next nextAll nextUntil siblings的區別,有興趣的朋友可以參考下

next:緊鄰$('')的一個元素

nextAll:在$('')以後的所有的同儕元素

nextUntil:until有直到。 。 。之前的意思,所以他表示$('')以後的所有的同儕元素,不過要在nextUntil參數之前,不包括匹配的元素本身

sibings:$('')前後的所有同儕元素

簡單理解就是,next就是找他的弟弟/妹妹,nextAll就是找他所有的弟弟/妹妹,nextUntil就是找比他小一定年紀的弟弟/妹妹,siblings就是找他所有的哥哥/姐姐,還有他的所有的弟弟/妹妹。所以同理的同儕關係,prev,prevAll ,prevUntil

下面是簡單的測試程式碼

程式碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
<title>
Document
</title> 
<script type=&#39;text/
javascript
&#39; src=&#39;http://code.jquery.com/jquery-1.9.1.min.js&#39;></script> 
</head> 
<body> 
<p class="first"> 
<a href="#">hhh</a> 
<h1>这是一个标题</h1> 
<p>这是一个test</p> 
<p>这是一个test</p> 
<p>这是一个test</p> 
<p>这是一个test</p> 
<p>hhha</p> 
<p>这是一个test</p> 
<p>这是一个test</p> 
</p> 
<script> 
$(function(){ 
//$(&#39;p
:first
&#39;).next().css(&#39;
background
&#39;,&#39;red&#39;); 
//$(&#39;p:first&#39;).nextAll().css(&#39;background&#39;,&#39;yellow&#39;); 
//$(&#39;p:first&#39;).nextUntil(&#39;p&#39;).css({&#39;
font-size
&#39;:20,background:&#39;red&#39;}); 
//$(&#39;p:first&#39;).siblings().css(&#39;background&#39;,&#39;yellow&#39;); 
}); 
</script> 
</body> 
</html>


####################################################

以上是簡述jquery中next、nextAll、nextUntil、siblings的差異與聯繫的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn