2013-07-08 2 views

답변

1

세포는 HTML에서 실제로 순차적없는, 그래서 당신은 단지 (nextAll 등으로) 동일한 수준으로 모두를 사용할 수 없습니다. 이 테이블이 말 :

<table> 
    <tbody> 
     <tr> 
      <td>one</td> 
      <td id="two">two</td> 
      <td>three</td> 
     </tr> 
     <tr> 
      <td>four</td> 
      <td>five</td> 
      <td>six</td> 
     </tr> 
    </tbody> 
</table> 

을 ... 그리고 당신이 two "후"모든 셀을 선택하려면,이 통과하고 그 셀을 선택합니다 :

$('table td:gt(' + $('#two').index() + ')').each(function() { 
    console.log($(this).text()); // or whatever you want to do with the cell 
}); 

데모 Fiddle here합니다.

-1
// Selecting all <td>s after <td id="i-want"> 
$('td#i-want ~ td') 

// Selecting the next <td> after <td id="i-want"> 
$('td#i-want + td') 
+0

'~'는 같은 부모를 가진 요소 만 선택합니다.이 경우에는 ''입니까? – jterry

0
아마

없는 가장 효율적인 솔루션,하지만 일을 가져옵니다

여기에서 기본 전략은 다음과 같습니다 현재 셀 후에, (b)는 행 요소에 모든 위해 점프 (가) 형제를 선택 현재 행 이후에 TD 행을 가져 와서 형제 목록에 추가하십시오.

<!doctype html> 
<html> 
<head><script src="../lib/jquery-1.9.1.js"></script> 
<style> 
table { border:1px solid black; } 
thead th { border-bottom:1px solid black; } 
tfoot th { border-top:1px solid black; } 
</style> 
<script> 
$(function() { 

    $('tbody').find('td') 
     .click(function(event) { 
      var $cell   = $(event.target), 
       $siblings  = $cell.nextAll('td'), 
       $remainingCells = $cell.closest('tr').nextAll().find('td'); 

      $siblings.add($remainingCells).each(function(index, element) { 
       console.info(index + ':', $(element).text()); 
      }); 
     }); 

}); 
</script> 
</head> 
<body> 
<table> 
    <thead> 
     <tr> 
      <th>#</th> 
      <th>A</th> 
      <th>B</th> 
      <th>C</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>1</td> 
      <td>Alpha</td> 
      <td>Bravo</td> 
      <td>Charlie</td> 
     </tr> 
     <tr> 
      <td>2</td> 
      <td>Delta</td> 
      <td>Echo</td> 
      <td>Foxtrot</td> 
     </tr> 
     <tr> 
      <td>3</td> 
      <td>Golf</td> 
      <td>Hotel</td> 
      <td>India</td> 
     </tr> 
    </tbody> 
    <tfoot> 
     <tr> 
      <th>#</th> 
      <th>A</th> 
      <th>B</th> 
      <th>C</th> 
     </tr> 
    </tfoot> 
</table>