이 스레드는 내 previous issue에서 다음 두 번째 문제입니다. 클릭 이벤트를 내 쇼 차트 기능에 바인딩 한 후에도 정확한 차트 데이터를 가져 오는 데 사용되는 직원 ID 값을 알아야합니다.jQuery로 표 셀의 값을 가져 오는 방법은 무엇입니까?
showChartByEmpId (i)에 직원 ID를 전달할 수 있습니까?
HTML
<table id="empTable" class="tablesorter">
<thead>
<tr>
<th> Employee ID </th>
<th> Name </th>
<th> Department </th>
<th> Title </th>
<th> Show Chart </th>
</tr>
</thead>
<tbody>
<tr>
<td> 101 </td>
<td> John </td>
<td> R&D </td>
<td> Engineer </td>
<td> <button class="doPieChart"> Pie Chart </button> </td>
</tr>
<tr>
<td> 102 </td>
<td> David </td>
<td> R&D </td>
<td> Engineer </td>
<td> <button class="doPieChart"> Pie Chart </button> </td>
</tr>
</tbody>
</table>
<div class="secondary"> </div>
JS 여기
function drawPieChart(i) {
$('.secondary').html('<div id="chart_div" class="div'+i+'">my graph '+(i+1)+' in fancybox</div>');
}
function showChart(i) {
drawPieChart(i);
}
function showChartByEmpId(i) {
showChart(i);
}
jQuery(function ($) {
//How to get emp Id here?
$(".doPieChart").each(function (i) {
$(this).on("click", function() {
showChartByEmpId(i);
$.fancybox("#chart_div");
}); // on click
}); // each
});
감사합니다. Anton. 이제 작동합니다. –