我有一個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