我建议您在两个单独的函数中执行此操作。
首先创建jquery数据表。
$(document).ready(function() {
$('#example').dataTable();
} );
创建你的表
echo ('<table id="example">');
echo ('<thead>');
echo ('<tr>');
echo ('<th>');
echo "First_name";
echo ('</th>');
echo ('<th>');
echo "Id";
echo ('</th>');
echo ('<th>');
echo "Delete";
echo ('</th>');
echo ('</tr>');
echo ('</thead>');
echo ('<tbody>');
foreach( ($data->user_info) as $row)
{
$first_name = $row['first_name'];
$user_id = $row['user_id'];
echo ('<tr>');
echo ('<td>');
echo ($first_name);
echo ('</td>');
echo ('<td>');
echo ($user_id);
echo ('</td>');
echo ('<td>');
echo "<button type="button" id= "delete">Delete</button>";
echo ('</td>');
echo('</tr>');
}
echo ('</tbody>');
echo ('</table>'); ?>
然后当您单击删除按钮时,您可以使用 jquery 获取行 ID ..
$("#delete").live("click", function()
{
var id = $("td:first", this).text(); // This will get the first column value ( id )
msg = "You are going to delete this " ;
title = "Delete name ";
OK = "OK";
cancel = "COM_CANCEL";
$('#showmsg-content').html(msg);
$("#showmsg").dialog
({
modal: true,
title: title,
width: 550,
buttons:{
OK : function()
{
you can send the id to the model using ajax
$.ajax({
url: url,
async: false,
data: "&id=" + id ,
type : 'post',
success : function()
{
//row is deleted , refresh the page
$(this).dialog('close');
},
});
$(this).dialog('close');
},
cancel : function(){
$(this).dialog('close');
}
},
});
} );
这应该有效。我没有测试这个..试一试..