jquery
[jQuery] td:eq(index) 테이블 선택 데이터 정보 가져오기
xemaker
2018. 10. 11. 13:37
':eq(index)'는 선택된 요소들을 인덱스 번호로 찾을 수 있는 선택자.
마치 배열의 인덱스로 값(value)를 찾는 것과 같음.
원문 링크 http://api.jquery.com/eq-selector/
<table class="" id="tempList">
<colgroup>
<col width="">
<col width="">
<col width="">
</colgroup>
<thead>
<tr>
<th class="">컬럼헤더0</th>
<th class="">컬럼헤더1</th>
</tr>
</thead>
<tbody>
<tr>
<td>컬럼0</td>
<td>컬럼1</td>
</tr>
</tbody>
</table>
위와 같이 테이블이 있다면
테이블 row를 클릭했을때 값을 가져오려면
jquery로
$("#tempList tbody").on("click", "tr", function(){
alert( $(this).find("td:eq(0)").text() );
alert( $(this).find("td:eq(1)").text() );
});
td:eq(0) -> 선택(클릭)한 row의 첫번째 데이터 -> 컬럼0
td:eq(1) -> 선택(클릭)한 row의 두번째 데이터 -> 컬럼1