Php 单击html表格';s删除列';s单元(td=x)
我有一个html表格,其中显示了列客户名称、员工名称和事项,而在我的数据库中,我有id、日期、客户名称、员工、事项列。这不是问题所在。我想删除按钮单击时的行,所以我只添加了一个列delete,其中包含id为“del”的按钮,是的,该列在我的数据库中不存在。现在我想删除表中的行以及相应按钮上的数据库,单击UsingjQuery。我该怎么做? 这就是我迄今为止所尝试的-Php 单击html表格';s删除列';s单元(td=x),php,jquery,html,mysql,Php,Jquery,Html,Mysql,我有一个html表格,其中显示了列客户名称、员工名称和事项,而在我的数据库中,我有id、日期、客户名称、员工、事项列。这不是问题所在。我想删除按钮单击时的行,所以我只添加了一个列delete,其中包含id为“del”的按钮,是的,该列在我的数据库中不存在。现在我想删除表中的行以及相应按钮上的数据库,单击UsingjQuery。我该怎么做? 这就是我迄今为止所尝试的- $(document).ready(function(){ $('#tableresult').on('click', '
$(document).ready(function(){
$('#tableresult').on('click', '#del', (function(){
var row = $(this).attr('id');
$(#tableresult).removeRow(row);
});
});
我的html-
<td class="delete_td"><button id="del" btn btn-danger>×</button></td>
×;
这是我的html表格代码-
<table class="footable" data-filter="#filter" id="tableresult">
<thead>
<th>Client name</th>
<th>Staff name</th>
<th>Matter</th>
<th> Delete</th>
</thead>
<?php
include('db.php');
$sql=mysql_query("select * from newdata");
while($row=mysql_fetch_array($sql))
{
$id=$row['id'];
$clientname=$row['client_name'];
$staff=$row['staff'];
$matter=$row['matter'];
?>
<tr id="<?php echo $id; ?>" class="edit_tr">
<td class="edit_td" >
<span id="client_<?php echo $id; ?>" class="text"><?php echo $clientname; ?></span>
<input type="text" value="<?php echo $clientname; ?>" class="editbox" id="client_input_<?php echo $id; ?>" />
</td>
<td class="edit_td">
<span id="staff_<?php echo $id; ?>" class="text"><?php echo $staff; ?></span>
<input type="text" value="<?php echo $staff; ?>" class="editbox" id="staff_input_<?php echo $id; ?>"/>
</td>
<td class="edit_td">
<span id="matter_<?php echo $id; ?>" class="text"><?php echo $matter; ?></span>
<input type="text" value="<?php echo $matter; ?>" class="editbox" id="matter_input_<?php echo $id; ?>"/>
</td>
<td class="delete_td"><button id="del" btn btn-danger>×</button></td>
</tr>
<?php
}
?>
</tbody>
<tfoot class="hide-if-no-paging">
<th> </th>
<th>
<div class="pagination pagination-centered"></div>
</th>
<th> </th>
<th> </th>
</tfoot>
</table>
客户名称
职员姓名
要紧
删除
你的js应该是
$(document).ready(function () {
$('#tableresult').on('click', '#del', (function () {
var row = $(this).attr('id');
$.ajax({
type: "GET",
url: 'http://yoursite_url/delete.php',
data: {id: row },
success: function (result) {
$('#'+row).remove();
}
});
});
});
和delete.php
include 'config.php' // DB Connection
$id = $_GET['id'];
$sql = mysql_query("DELETE FROM TABLE_NAME WHERE id = '$id'");
试试这个
$("#del").click(function () {
var row = $(this).attr('temp_id');
$.ajax({
type: "GET",
url: 'http://yoursite_url/delete.php',
data: {id: row},
success: function (result) {
$('#row').remove();
}
});
});
像这样换按钮
<button id="del" temp_id="<?php echo $id; ?>" class="btn btn-danger">×</button>
你应该调用ajax来实现这一点。我不太习惯使用ajax。所以请指导我使用它。你是说每行都有自己的删除按钮吗?如果单击,关联的行将从html和数据库中删除?是的。它们有相应的del按钮根据您在整个tr
标记上应用的代码编辑操作。当它应该在特定列上时。发生的情况是,每当我单击特定表行时,它会自动切换到编辑模式,如果我单击列中的“删除”按钮,也会发生同样的情况,但是不删除任何东西Bro你不认为你只是复制了我的全部代码。我只做了一点小改动,即获取已删除行的id。。如果你觉得对不起。。
<button id="del" temp_id="<?php echo $id; ?>" class="btn btn-danger">×</button>