第一个问题:
当用户删除特定行时,我必须仅删除该行而不刷新页面。使用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>
Run Code Online (Sandbox Code Playgroud)
您可以使用 jQuery 的nth-child选择器。
$("table#mytableid tr:nth-child(2)").remove();
Run Code Online (Sandbox Code Playgroud)
例如,这将删除第二行。确保您的表格有一个 ID 或类,以便您更轻松地选择它(不要意外删除页面上每个表格的第二行,以防您有更多表格)...
编辑
从我在代码中看到的,您可以从 onclick 事件中选择父 tr 元素,然后将其作为新参数发送到函数(您将在 ajax 返回成功时将其删除)或立即将其删除...或者任何你想要的。
| 归档时间: |
|
| 查看次数: |
3990 次 |
| 最近记录: |