这个线程是我上一期之后的第二个问题。将 on click 事件绑定到我的 show-chart 函数后,我仍然需要知道用于获取正确图表数据的员工 ID 的值。
是否可以将员工 ID 传递给 showChartByEmpId(i) ?
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
});
这是我在 JSFIDDLE上的示例