2013-08-29 3 views
0

검색 필드가있는 테이블이 있습니다. 데이터를 검색 한 후 나열된 데이터를 Excel로 내보내고 표에 표시되지 않은 추가 정보가 필요하므로 데이터베이스에서 가져와야합니다. 그래서 목록에있는 모든 데이터에 액세스해야합니다 (seraching 후). 또한 태그에는 관련 'id'또는 'class'가 없으므로 데이터 테이블을 사용하여 렌더링되었으므로 태그를 가져올 수 있습니다. 어떻게 이런 일이 JQuery와테이블 헤더에서 요소를 가져옵니다.

코드

<table id='mytable' border='1'> 
    <tr> 
     <th id='ID'>ID</th> 
     <th id='Email'>Email</th> 
    </tr> 
    <tr> 
     <td>1</td> 
     <td>[email protected]</td> 
    </tr> 
    <tr> 
     <td>2</td> 
     <td>[email protected]</td> 
    </tr> 
    <tr> 
     <td>3</td> 
     <td>[email protected]</td> 
    </tr> 
</table> 

<button id='gen'>Generate excel file</button> 

을 사용하여 달성 할 수 jsfiddle : 그것은 http://jsfiddle.net/xLA3g/3/

$('#mytable tr th').each(function(i){ 
    alert($(this).text()); 
}); 

답변의 UPDATE하는 데 도움이 수도 http://jsfiddle.net/xLA3g/2/

답변

1

이, 이것 좀 봐, td 열 번호 표시 http://jsfiddle.net/xLA3g/4/

$('#mytable tr td:first-child').each(function(i){ 
    alert($(this).text()); 
}); 

이 단지에만 테이블 헤더를 보여 주었다 .... 내가 더

+0

감사 답변을 수정 도움을 도울 수 있다면 알려주세요. 이 예제에서는 1,2,3과 같은 ID를 추출하려고합니다. – beebek

+0

예, 두 번째 대답은 해결책입니다. 대단히 고마워요 @caramba – beebek

+0

다른 사람들을 위해 jsfiddle에 완벽한 솔루션을 게시했습니다 .. http://jsfiddle.net/keJBZ/3/ – beebek

1

조금 @carambas가

var ids=[]; 
$('#mytable tr th').each(function(i){ 
    alert($(this).attr('id')); 
    ids.push($(this).attr('id')); 

}); 
console.log("ID",ids); 
관련 문제