如何使用jQuery查找下一个元素,直到找到一个或两个元素

如何使用jQuery查找下一个元素,直到找到一个或两个元素,jquery,Jquery,我在jquery中有这个选择器 $(ptr).nextUntil('tr.item').fadeOut('slow', function() { $(this).remove(); }); 但是我想做这样的事情 $(ptr).nextUntil('tr.item' OR 'tr.ptype').fadeOut('slow', function() { $(this).remove(); }); $(ptr).ne

我在jquery中有这个选择器

$(ptr).nextUntil('tr.item').fadeOut('slow', function() {
            $(this).remove();
        });
但是我想做这样的事情

$(ptr).nextUntil('tr.item' OR 'tr.ptype').fadeOut('slow', function() {
            $(this).remove();
        });
$(ptr).nextUntil('tr.item,tr.ptype').fadeOut('slow', function() {
        $(this).remove();
    });
我已经尝试过此选择器,但它无法正常工作:

 $(ptr).nextUntil('tr.item, tr.ptype').fadeOut('slow', function() {
        $(this).remove();
    });
例如,有两种情况,它应该删除所有tr.add_tr元素,直到找到tr.item或tr.ptype的一致性

CASE 1



<tr class="item"></tr> <!-- i'm here -->
<tr class="add_tr"></tr> <!-- remove it -->
<tr class="add_tr"></tr><!-- remove it -->
<tr class="add_tr"></tr><!-- remove it-->
<tr class="ptype"></tr> <!-- don't remove it-->
<tr class="item"></tr> <!-- don't remove it-->
<tr class="add_tr"></tr> <!-- don't remove it-->
<tr class="add_tr"></tr> <!-- don't remove it-->
<tr class="add_tr"></tr> <!-- don't remove it-->
<tr class="add_tr"></tr> <!-- don't remove it-->
<tr class="add_tr"></tr> <!-- don't remove it-->




CASE 2

<tr class="item"></tr> <!-- i'm here -->
<tr class="add_tr"></tr> <!-- remove it -->
<tr class="add_tr"></tr><!-- remove it -->
<tr class="add_tr"></tr><!-- remove it-->
<tr class="item"></tr> <!-- don't remove it-->
<tr class="add_tr"></tr> <!-- don't remove it-->
<tr class="add_tr"></tr> <!-- don't remove it-->
<tr class="add_tr"></tr> <!-- don't remove it-->
<tr class="add_tr"></tr> <!-- don't remove it-->
<tr class="ptype"></tr> <!-- don't remove it-->
<tr class="item"></tr> <!-- don't remove it-->
<tr class="add_tr"></tr> <!-- don't remove it-->
案例1
案例2

你能帮我吗。

你可以这样使用:

    $(ptr).nextUntil('tr.item, tr.ptype').fadeOut('slow', function() {
        $(this).remove();
    });

我想您可以在元素之间添加冒号。像这样的

$(ptr).nextUntil('tr.item' OR 'tr.ptype').fadeOut('slow', function() {
            $(this).remove();
        });
$(ptr).nextUntil('tr.item,tr.ptype').fadeOut('slow', function() {
        $(this).remove();
    });

让我知道这是否有效?

请看这个。这是基于Lalji的答案。它不起作用,因为它必须停止查找tr.ptype或tr.item为什么$(ptr.nextUntil('tr.item,tr.ptype')不起作用?我对它进行了测试,结果它对我有效。我的示例中的fiddle:它不起作用,因为它必须停止查找tr.ptype或tr.item