next():用來(lái)獲取下一個(gè)同輩元素。
prev():用來(lái)獲取上一個(gè)同輩元素。
siblings():用來(lái)獲取所有的同輩元素。
<!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> <title>jQuery中的節(jié)點(diǎn)遍歷next下一個(gè)、prev上一個(gè)、siblings兄弟</title> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { //next()方法用于獲取節(jié)點(diǎn)之后的 挨著 的第一個(gè)同輩元素 //參數(shù)為空顯示挨著 的第一個(gè)同輩元素 參數(shù)不為空就行匹配,如是參數(shù)元素顯示,如不是顯示空 //$(this).next("p").text() 點(diǎn)擊aaaa返回彈出空 點(diǎn)擊cccc顯示dddd $("p").click(function() { alert($(this).next("p").text()); }); //nextAll()nextAll()方法用于獲取節(jié)點(diǎn)之后的所有同輩元素 //參數(shù)為空顯示所有同輩元素的值 參數(shù)不為空就匹配,如是參數(shù)元素顯示,如不是顯示空 //$(this).nextAll().text() 點(diǎn)擊aaaa返回彈出bbbbccccdddd 點(diǎn)擊cccc顯示dddd //$(this).nextAll("p").text() 點(diǎn)擊aaaa返回彈出ccccdddd 點(diǎn)擊cccc顯示dddd $("p").click(function() { alert($(this).nextAll("p").text()); }); //prev、prevAll兄弟中之前的元素。 與next、nextAll相反 $("p,p").click(function() { alert($(this).prev().text()); alert($(this).prevAll().text()); alert($(this).prev("p").text()); alert($(this).prevAll("p").text()); }); //siblings()方法用于獲取所有同輩元素 $("p,p").click(function() { alert($(this).siblings().text()); alert($(this).siblings("p").text()); }); }) //案例:選中的p變色 $(this).css();$(this).siblings().css() //案例:評(píng)分控件。prevAll,this,nextAll </script> </head> <body> <p> aaaa</p> <p> bbbb</p> <p> cccc</p> <p> dddd</p> </body> </html>
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com