2013-05-22 64 views
0

中的第一行我尝试将用户重定向到其他页面,但如果他/她单击表格中的5,8或最后一个单元格,则不会发生任何事情。第一排没关系。但其他行不起作用。jQuery .eq()仅适用于表

$("#table td:not(:last-child,:eq(5),:eq(8))").click(function(){ 
     var url = $(this).parent().find('td:last-child a[title="edit"]').attr('href');   
     if (url != undefined) { 
      location.href = $(this).parent().find('td:last-child a[title="edit"]').attr('href'); 
     } 
    }); 
+2

:EQ选择通过集合中的索引,父之内没有索引。尝试:nth-​​child() –

+3

也许你应该使用类而不是第5和第8行。 – jantimon

+0

@KevinB那么我怎样才能分别影响所有行 –

回答

0

使用代表团

$("#table").on('click', 'td', function(){ 
    var $this = $(this); 
    if ($this.index() === 4 || $this.index() === 7 || $this.is(':last-child')) return; 
    var url = $this.nextAll('td:last-child a[title="edit"]').attr('href');   
    if (url != undefined) { 
     location.href = $this.nextAll('td:last-child a[title="edit"]').attr('href'); 
    } 
    return false 
}); 
+0

它的工作。非常感谢。但我只是改变if语句中的索引号。 4至5和7至8。 –