2011-12-02 143 views
3

第一個問題刪除表particualr行:我怎麼能使用jquery

當用戶刪除特定行的話,我不得不刪除該行只出刷新頁面。 使用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> 

回答

3

您可以使用jQuery的nth-child選擇。

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

例如,這將刪除第二行。確保讓您選擇更容易的表有一個ID或類(不意外刪除頁面上的每個表的第二行,如果你有更多的)...

編輯

從什麼我在你的代碼中看到,你可以從你的onclick事件中選擇父tr元素,然後把它作爲一個新參數發送給函數(你可以將它移除,然後ajax返回成功),或者馬上刪除它......或者其他任何東西你要。

+0

我不得不刪除沒有第二行用戶刪除的行 – vvr

+1

我只是給你一個例子......你可以找到已刪除的行的行號,並把那個,而不是2或assing一個ID的行一旦刪除,然後使用vikky的方法。 – Shomz

+0

您可以使用該特定點擊元素的索引。 – punit

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

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