是否可以在jQuery中使用复杂的选择器:not()?

时间:2017-10-23 10:01:50

标签: jquery

我想在Trello页面上选择和计算一些元素。我想在一行中完成所有这些工作,使用类似的东西:

$('.js-list.list-wrapper').each(function(index){
  var numberOfTickets = $(this).find('.list-card:not(div > .list-card-details > .list-card-title:contains("LIMIT: 8"))').length;        
});

因此,我想从每列中选择所有.list-card,但不要选择.list-card-title内包含" LIMIT:8" 文字的内容。从理论上讲,它应该运作良好,但我无法在互联网上找到像上面所示的用法。这样使用它是否合适?

编辑:

jsFiddle:https://jsfiddle.net/hr9cpc1m/

2 个答案:

答案 0 :(得分:3)

我会使用filter()让这更容易阅读

var numberOfTickets = $(this).find('.list-card').filter(function(){
    return !$(this).find('.list-card-title:contains("LIMIT: 8")').length;
}).length;

答案 1 :(得分:2)

您可以将:has() selector:not() selector

结合使用
var numberOfTickets = $(this).find('.list-card:not(:has(div > .list-card-details > .list-card-title:contains("LIMIT: 8")))').length;
相关问题