이렇게하는 방법에는 여러 가지가 있습니다. 가장 쉬운 방법은 테이블에서 groupid를 찾는 방법이 필요하므로 테이블 구조를 약간 변경해야합니다. 당신이 nth-child(3)
또는 eq(-1)
같은 유연성이 기술을 사용할 필요가 없습니다 것이다 제외하고
<tr>
<td>1</td>
<td>Jack</td>
<td class='groupId'>1</td>
</tr>
그런 다음 당신은 다른 답변과 유사하여 자바 스크립트를 작성합니다 : 당신은이 같은 그룹 ID가 들어있는 셀에 클래스를 추가한다 무엇을 할 수 있는지 . 이것은 자바 스크립트를 변경하는 데 더 유연하게 만듭니다.
이 같은 끝낼 수 :
function hideRows(){
// find selected value (get only the first as multi-selected is not required)
var selected = $('#groups option:selected')[0].value;
// walk through all cells that have the groupId class
$('#myTable td.groupId').each(function(){
// get current cell
var currentCell = $(this);
// get the cells groupid
var groupid = currentCell.text();
// determine if it the group id matches the selected value and hide/show
if(groupid !== selected){
currentCell.parent().hide();
}
else{
currentCell.parent().show();
}
});
}
// wire-up select change event
$('#groups').change(hideRows);
을 올바른 열을 aquire하는 상기 기술 중 하나에 의지해야하는 테이블의 그룹 ID 세포를 분리 할 수있는 방법이 없다면.
JSFiddle - http://jsfiddle.net/GFzcp/5/