第一个问题:
当用户删除特定行时,我只需要在不刷新页面的情况下删除该行。 使用ajax删除行。我该怎么做
第二个问题: 实际上,我正在计算从那天到前 7 天的页面点击时间。 但我想当今天页面点击时我必须检索前一周 表示从周日(2011 年 11 月 20 日)到周六(2011 年 11 月 20 日) 当页面在下周一点击时,我必须检索本周记录 表示从周日(2011 年 11 月 27 日)到周六(2011 年 12 月 3 日)
function authenticate(){
$.ajax({
type: "POST",
url: "authentication.php",
data: $("#login_form").serialize(),
success: function(msg){
if(msg==1){
$('#delete').html("success"); //if success message appear only i have to remove particular row
})
}else{
$('#delete').html("error");
}
},
error:function(msg){
alert(msg);
$('#delete').dialog("close");
}
});
}
<div style='display: none;' id='delete'></div>
<table border="1">
<tr>
<th>Title</th>
<th>Public Id</th>
<th>Pass</th>
<th></th>
</tr>
<?php
$select = $db->select ()
->from ( 'test', '*' )
->where ( 'user_id = ?', 1 )
->where ( 'test.created > DATE_SUB(CURDATE(), INTERVAL 7 DAY)' );
$tourDetails = $db->fetchAll ( $select );
$i = 0;
foreach ( $tourDetails as $row1 ) {
$i ++;
$title = $row1 ['title'];
$PublicId = $row1 ['public_id'];
if (($i % 2) == 0 ) {
$rowResponse = prepareRow ( true, $title, $PublicId);
echo $rowResponse;
} else {
$rowResponse = prepareRow ( false, $title, $PublicId);
echo $rowResponse;
}
}
function prepareRow($flag, $title, $PublicId) {
$rowResponse = "";
if ($flag) {
$rowResponse .= '<tr class="even">';
} else {
$rowResponse .= '<tr class="odd" >';
}
$rowResponse .= '
<td> ' . $title . ' </td>
<td> ' . $publicId . ' </td>
<td><p><a onclick=openDialog("'. $PublicId .'","delete") href="#" id="dialog_link">
Delete </a></p>
</td>';
return $rowResponse;
?>
</table>
最佳答案
您可以使用 jQuery 的 nth-child选择器。
$("table#mytableid tr:nth-child(2)").remove();
例如,这将删除第二行。确保你的表有一个 ID 或一个类,这样你就可以更容易地选择它(不要不小心删除页面上每个表的第二行,以防你有更多)...
编辑
根据我在您的代码中看到的情况,您可以从您的 onclick 事件中选择父 tr 元素,然后将其作为新参数发送到该函数(您将在 ajax 返回成功时将其删除)或立即将其删除...或任何你想要的。
关于php - 我如何使用 jquery 从表中删除特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8352564/