简体   繁体   English

需要JQuery帮助选择表行数组(tr)

[英]Need JQuery help selecting an array of table rows (tr)

Here is the code snippet: http://jsbin.com/ekupa3/2/edit 这是代码段: http : //jsbin.com/ekupa3/2/edit

I need to return the table rows (tr) that don't have a tag of 'test2'. 我需要返回没有标签“ test2”的表行(tr)。 the output should be an array of table rows (tr). 输出应为表行(tr)的数组。

I spent a couple hours trying every JQuery technique I knew and I will bow to the experts. 我花了几个小时来尝试我所知道的每种JQuery技术,然后向专家们鞠躬。

var newTag = 'test2';
var rows_without_newTag = $("table tr").not(":contains(" + newTag + ")");

Created an edit of the OP's JS Bin w/ some example usage for posterity's sake. 为了后代的缘故, 创建了带有某些示例用法的OP的JS Bin的编辑

var newTag = 'test2',
    $tr = $('tr').filter(function() {
        return $(this).html().indexOf('>' + newTag + '</a>') == -1;
    });

$tr will be a jQuery element array containing all tr not containing the tag test2 . $tr将是一个jQuery元素数组,其中包含所有不包含标签test2 tr I included parts of the HTML in the indexOf check in case there was another tag called "another-test2" or the like. 我将HTML的一部分包含在indexOf检查中,以防出现另一个名为“ another-test2”或类似标签的情况。

See example → 参见示例→

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM