【问题标题】:How to select 2nd to 4th td from a row inside jQuery selector如何从 jQuery 选择器中的一行中选择第 2 到第 4 个 td
【发布时间】:2013-08-18 21:49:14
【问题描述】:

我有一个复选框表,我想从一行 7 个 td 中选择第 2 到第 4 个 td。 具体来说,我想选择表格中第一行的输入:第 2 到第 4 td 的复选框,

到目前为止我的代码

$('tr:nth-child(1) td:gt(2) input:checkbox')

有什么建议吗?

谢谢

【问题讨论】:

标签: jquery checkbox jquery-selectors


【解决方案1】:

你可以使用slice方法:

$('tr:first td').slice(1, 4).find('input[type=checkbox]');

【讨论】:

    【解决方案2】:

    你可以使用:

    $('tr:nth-child(1) td:nth-child(-n + 4):nth-child(n + 2) input:checkbox')
    

    http://jsfiddle.net/erWp9/2/

    【讨论】:

    • 它看起来很棒,并且在您的代码上效果很好,但在我的代码上没有。我的是 var $radio5 = $('tr:nth-child(1) td:nth-child(-n + 4):nth-child(n + 2) input:checkbox'); $radio5.change(function(){ var $group = $radio5; if($(this).is(':checked')){ $group.not($(this)).prop('checked',false ); } });知道为什么它不起作用吗?
    【解决方案3】:
    $('tr td').filter(function(){
        return $(this).index() > 0 && $(this).index() < 4;
    });
    

    Here's your jsFiddle

    【讨论】:

      【解决方案4】:

      你最好依赖 jquery 的方法:

      $("tr").eq(1).find("td").find("input[type='checkbox']")
      and
      $("tr").eq(3).find("td").find("input[type='checkbox']")
      

      【讨论】:

        猜你喜欢
        • 2023-03-24
        • 1970-01-01
        • 1970-01-01
        • 2015-01-03
        • 1970-01-01
        • 2014-11-11
        • 2016-11-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多