2013-05-22 2 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이다. –

관련 문제