jquery选择并排除多个nth-childs

时间:2012-05-28 22:30:14

标签: javascript jquery find css-selectors

有没有办法可以一次选择多个n-childs,如:

    $("#table").find("tr > :not(td:nth-child(1,3,5))");

哪个不起作用

我想在每行中选择所有td,但不要选择第1,3,5列(这可以是任意组合)。

有办法做到这一点吗?我无法分配类名。

感谢您的帮助!

更新:

我想搜索表格的所有行,但不包括某些列。

我现在有这个代码:

    elem.keyup(function() {

    $(options.table).find("tr").hide();
    var data = this.value.split(" ");
    var jo = $(options.table).find("tr > :not(td:nth-child("+cols+"))");

    $.each(data, function(i, v){

    jo = jo.filter(":containsIgnoreCase('"+v+"')");

    });

    jo.parent().show();
    });

当我传递单个值时它会起作用,但我想排除多个列。

感谢

1 个答案:

答案 0 :(得分:1)

从您的示例中,您似乎试图排除奇数。尝试:

$("#table").find("tr > :not(td:nth-child(odd))");

虽然,选择偶数可能更有效。

$("#table").find("tr > td:nth-child(even)");

您也可以在nth-child中使用公式。 See this link for more detail.

好的,根据下面的评论/对问题的澄清,这是另一种解决方案。

$("#table").find("tr > td").filter(function(index){
   return index == 1 || index == 2 || index == 5;   
});