簡體   English   中英

如何結合has()和gt()

[英]How to combine has() and gt()

使用jQuery 1.4.2,我不知道如何將has()與:gt結合使用。 我想選擇任何<ul>包含超過3 <li> S,所以這里就是我的嘗試:

$(document).ready(function(){  
  $("ul.collapse:has(li:gt(2))")  
    .each( function() {  
       $(this).css("border", "solid red 1px");  
  });  
});  

確實適用於1.2.6 jQuery庫,但不適用於1.3.2或1.4.2。 為什么?

嘗試使用nth-child

$('ul').has('li:nth-child(3)').css('border', 'solid red 1px');

工作示例: http : //jsbin.com/opape3

該選擇器由於某些原因而無法工作: $("ul.collapse:has(li:nth-child(3))")

試試.filter()

$("ul").filter(function(){
    return $(this).find("li").length > 4;
}).each(function(){
    // your code   
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM