伙计我有一个var广告,它存储了来自数据库的所有ID,并且我使用该var广告作为post中的参数来删除删除页面中表格中的特定行。现在当我点击一个按钮时,它只删除一个表的最后一行。我做了一些调试,发现每次我点击一个按钮发送最后一个元素的ID,但我想删除/发送点击行的ID。请查看下面的代码获取更多信息任何帮助将非常感谢。
function something() {
for (var i = 0; i < (testvalues.length); i = i + 2) {
//my logic
var ad = testvalues[i + 4]; //list of ID'S from DB[1,2,3....]
}
$(".sukuti").click(function() {
//here im passing ad=id as a parameter
$.post("delete.jsp", {
id: ad
}, function(data) { //everytime its sendind the ID of the row so last row is being deleted i need to delete the particular row which is being clciked.
//this post goes to delete page which have query to delete
});
});
<button class="sukuti" type="button">
答案 0 :(得分:0)
因为您没有显示您的真实代码,所以我们创建一个方案来帮助您。
$(".sukuti").click(function(){
var rowId = $(this).closest('tr').find('td.id').text();
console.log("Id found:", rowId);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td class="id">10</td>
<td><a href="javascript:;" class="sukuti">Remove</a></td>
</tr>
<tr>
<td class="id">11</td>
<td><a href="javascript:;" class="sukuti">Remove</a></td>
</tr>
<tr>
<td class="id">12</td>
<td><a href="javascript:;" class="sukuti">Remove</a></td>
</tr>
<tr>
<td class="id">13</td>
<td><a href="javascript:;" class="sukuti">Remove</a></td>
</tr>
</tbody>
</table>
&#13;