2011-04-07 1 views
0

다른 테이블에있는 버튼을 클릭 할 때 테이블을 전환 (숨기기/표시)하려고하지만 선택하는 데 어려움이 있습니다. 그것 올바르게. 동일한 스크립트에서 여러 번 재사용해야하기 때문에 jQuery 코드를 일반화하려는 경우 의도적으로 id 태그를 남겨 두었습니다.jQuery - parents()를 통해 다른 테이블의 버튼에서 테이블 요소를 토글합니다

http://jsfiddle.net/Argoron/Dp2sk/24/

답변

1
$(document).ready(function() { 

    $('button.new_disp').toggle(
    function() { 
     $(this).closest('table').next('table').hide(); 
     $(this).text('Show'); 
    }, function() { 
     debugger; 
     $(this).closest('table').next('table').show(); 
     $(this).text('Hide'); 
    });   
}); 
0

이 시도 : 내가 지금까지 가지고 그 다음에

td에서

을 - 첫째 부모를 얻을>table -> 다음 형제 table를 얻을 -> 표시/숨기기 :

$('button.new_disp').toggle(

function() { 
    $(this).parents('table').next('table').hide(); 
    $(this).text('Show'); 
}, function() { 
    $(this).parents('table').next('table').show(); 
    $(this).text('Hide'); 
}); 
관련 문제