【发布时间】:2018-09-16 21:52:45
【问题描述】:
我尝试了几种方法来获取表格中单击按钮的行索引。
桌子:
while ($info = mysqli_fetch_array($sql)) {
echo "<tr>";
echo "<th>{$info['name']}</th>";
echo "<th>{$info['pass']}</th>";
echo "<th><a href='http://{$info['link']}'>{$info['link']}</a></th>";
echo "<th><div class='delbuttons'><button class='btn btn-info' data-toggle='modal' data-target='#myModal' id='{$info['id']}'>Delete</button></div></th>";
echo "</tr>";
}
?>
这些是我尝试过的方法:
$(document).on('click', '.delbuttons button', function(event) {
alert($(this).index());
}
但它总是返回 -1。
$(document).on('click','.delbuttons button', function(event) {
alert(this.rowIndex);
}
这会返回 undefined。
【问题讨论】:
-
欢迎回来:-)。 -- 为什么是
<th>而不是<td>?
标签: javascript jquery html-table onclick row