如何使用jquery从表中删除刨花行

时间:2022-09-16 09:48:15

First Problem:

第一个问题:

When user deleted particular row then i have to remove that row only with out page refresh. Deleting row using ajax. How can i do this

当用户删除特定的行时,我必须只删除行而不刷新页面。使用ajax删除行。我该怎么做呢

Second Problem: Actually i am calculating the when ever page hits from that day to previous 7 days. But i want when page hits today i have to retrieve previous week Means from sunday(20 Nov 2011) to saturday (20 Nov 2011) When page hits on next monday so i have to retrieve this week records Means from sunday(27 Nov 2011) to saturday (03 Dec 2011)

第二个问题:实际上我正在计算从那天到前7天的页面点击量。但是我想要当今天页面被打开时我必须找回上一周的意思从周日(2011年11月20日)到周六(2011年11月20日)下星期一页面被打开所以我必须找回这周记录的意思是从周日(2011年11月27日)到周六(2011年12月03日)

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>

2 个解决方案

#1


3  

You can use jQuery's nth-child selector.

您可以使用jQuery的第n个子选择器。

$("table#mytableid tr:nth-child(2)").remove();

This will remove the second row, for example. Make sure your table has an ID or a class so that you select it more easily (not accidentally removing 2nd row of EVERY table on the page, in case you have more)...

例如,这将删除第二行。确保您的表具有ID或类,以便您更容易地选择它(不要意外地删除页面上每个表的第2行,以防您有更多的表)……

EDIT

编辑

From what I see in your code, you could select the parent tr element from your onclick event and then either send it to the function as a new parameter (which you would remove it the ajax returns success) or remove it right away... or whatever you want.

从您的代码中可以看到,您可以从onclick事件中选择父tr元素,然后将它作为一个新的参数发送给函数(您将删除它,ajax返回success),或者立即删除它……或任何你想要的。

#2


0  

$('#myTableRow').remove(); 

 This works fine if your row has an id, such as:
<tr id="myTableRow"><td>blah</td></tr> 

#1


3  

You can use jQuery's nth-child selector.

您可以使用jQuery的第n个子选择器。

$("table#mytableid tr:nth-child(2)").remove();

This will remove the second row, for example. Make sure your table has an ID or a class so that you select it more easily (not accidentally removing 2nd row of EVERY table on the page, in case you have more)...

例如,这将删除第二行。确保您的表具有ID或类,以便您更容易地选择它(不要意外地删除页面上每个表的第2行,以防您有更多的表)……

EDIT

编辑

From what I see in your code, you could select the parent tr element from your onclick event and then either send it to the function as a new parameter (which you would remove it the ajax returns success) or remove it right away... or whatever you want.

从您的代码中可以看到,您可以从onclick事件中选择父tr元素,然后将它作为一个新的参数发送给函数(您将删除它,ajax返回success),或者立即删除它……或任何你想要的。

#2


0  

$('#myTableRow').remove(); 

 This works fine if your row has an id, such as:
<tr id="myTableRow"><td>blah</td></tr>