最接近的问题我有一个代码可以在.click()中工作,但只适用于第一行。 我需要使用与数据动态生成相同的ID。
代码完美适用于第一行..并抓取TR ID,但不适用于第二行左右。。jquery/php
<tr id="25">
<td>25</td>
<td>asd</td>
<td>gjkhgkj</td>
<td></td>
<!-- more td's -->
<td id="edit" name="25">Edit</td>
<td id="delete" name="25">Delete</td>
</tr>
<tr id="24">
<td>24</td>
<td>hhh</td>
<td></td>
<!-- more td's -->
<td id="edit" name="24">Edit</td>
<td id="delete" name="24">Delete</td>
</tr>
该函数删除客户数据:
$('#delete').click(function(e) {
var bid = this.id; // button ID
var customerid = $(this).closest('tr').attr('id'); // table row ID
$.ajax({
type: "POST",
url: "delete.php",
data: "id="+customerid+"",
success: function(msg){
// $('#'+customerid).css({backgroundColor: 'red'});
$('#'+customerid).remove();
alert("Sucessfully Deleted.")
// $('#tabledata').load('load.php');
}
});//end of $ajax