我有一个html表,它包含每行上的一个按钮。当我点击那个按钮时,我想获得该行的索引。用我的代码我得到的索引值,但它从1开始,而不是0.在其他例子中,我看到行索引是从值“0”开始,但在我的情况下,它从“1”开始。任何人都可以帮助我,我犯了错误。我如何找到表中的行索引
这是我的桌子。
<div class="table-style table-municipality table-edit-community-view">
<table id="sum_table">
<tr class="titlerow">
<th>S.N.</th>
<th>Community</th>
<th>Address</th>
<th>Area</th>
<th>Estimated</th>
<th>Total</th>
<th>Action</th>
</tr>
<?
$sn = 1;
while($result= mysql_fetch_row($res))
{
?>
<tr id="<?php echo $result[0];?>">
<td align="center"><? echo $sn++; ?></td>
<td align="center"><? echo $result[1] ?></td>
<td align="center"><? echo $result[2] ?></td>
<td align="center" class="rowDataSd"><? echo $result[3] ?></td>
<td align="center" class="rowDataSd"><? echo $result[4] ?></td>
<td align="center" class="rowDataSd"><? echo $result[5] ?></td>
<td>
<button class="test">Test</button>
</td>
</tr>
<?
}
?>
</table>
</div>
脚本:
$(".test").click(function(){
console.log("name: ", $(this).closest('td').parent()[0].sectionRowIndex);
});
是的,我已经与TR尝试,以及但我得到相同的结果。 – nas