jQuery-編輯選擇結果(添加、篩選、過濾或檢測)

來源:互聯網
上載者:User

標籤:

編輯選擇結果
操作  執行個體  效果  備忘

添加

添加選取器 $("p").add(".a") 添加類名為a的選取器 並不影響源結果集    
$("p").add( "label", $(".class") ); 添加類包含名為class的所有label元素的選取器
添加html對象 $("p").add( document.getElementsByTagName("label")) 添加元素名為label的html對象
添加jquery對象 $("p").add( $("strong")) 添加元素名為strongl的jquery對象

篩選   

擷取元素    $("p").first() 擷取第一個元素  
$("p").last() 擷取最後一個元素  
$("p").eq(3) 擷取第3個元素 可以為負,表倒數
擷取子集 $("p").slice(2) 擷取第2個元素直至結果集末尾組成的結果集  
$("p").slice(2,5) 擷取第2-5個元素組成的結果集  

過濾

當前

得到對應元素 $("p").filter(".aa") 得到含有類名為aa的結果集  
$("div").filter(document.getElementsByTagName("label")) 得到含有label元素的結果集  
$("div").filter($test) 得到含有$test對象的結果集  
$("div").filter(function(index){if(this.id=="xixi"){ return true;}else{return false;}}) 遍曆結果集,得到false傳回值則剔除 index是索引,this代表當前對象
除去對應元素 $("p").not(".aa")   與filter正好相反    
$("div").not(document.getElementsByTagName("label"))  
$("div").not($test)  
$("div").not(function(index){})  

後代

得到含有合格後代元素的結果集

$("div").has(".aa")  後代中含有類名為aa的結果集 判斷的對象是後代元素  
$("div").has(document.getElementsByTagName("label"))  後代中含有元素名為label的結果集
檢測 返回true或false $("#div1").is("div") 參數是源結果集的父集時返回true  
$("#div1").is(document.getElementsByTagName("div"))
$("#div1").is($test)
$("#div1").is(function(index){if(this.id=="xixi"){ return true;}else{return false;}}) index是索引,this代表當前對象

參考資料:http://www.365mini.com/page/jquery-add.htm

jQuery-編輯選擇結果(添加、篩選、過濾或檢測)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.