2009-12-05 76 views
0

我有以下MySQL的刪除按鈕。如何添加警告模式刪除

DELETE FROM mytable 
WHERE id = $id 

我想添加一個jquery模式來確認繼續。 「你確定要刪除嗎?是|否」

如果你點擊是,那麼它將執行刪除,如果它是否則退出模式並返回到頁面。

每個錨點中的id是動態添加的。

echo anchor('admin/categories/delete/'.$list['id'],'delete',array('class' => 'modalInput')); 

此輸出以下html。

HTML,

... 
<tr valign='top'> 
<td>1</td> 
<td>Forsiden</td> 

<td align='center'>active</td> 
<td align='center'><a href="http://127.0.0.1/test/index.php/admin/categories/edit/1">edit</a> | <a href="http://127.0.0.1/test/index.php/admin/categories/delete/1">delete</a></td> 
</tr> 
<tr valign='top'> 
<td>2</td> 
<td>Front top</td> 
<td align='center'>active</td> 
<td align='center'><a href="http://127.0.0.1/test/index.php/admin/categories/edit/2">edit</a> | <a href="http://127.0.0.1/test/index.php/admin/categories/delete/2">delete</a></td> 

</tr> 
... 

什麼是做這種方式嗎?

回答

3
< script type="text/javascript"> 
<!-- 
function confirmation() { 
    var answer = confirm("Are you sure you want to delete?") 
    if (answer){ 
       $.post('/delete/post', {id: '345'}); 
    } 
} 
//--> 
< /script> 

可能是這樣的事情。你將不得不通過在「345」是數據...

1

一種辦法是給刪除鏈接的一類,然後你可以做這樣的事情:如果你

// simple solution 
$('.delete_link').click(function() { 
    // if the user clicks "no", this will return false, stopping the link from being triggered 
    return confirm("Are you sure you want to delete?"); 
}); 

要刪除與阿賈克斯的情況發生:

// ajax soluction 
$('.delete_link').click(function() { 
    if (confirm("Are you sure you want to delete?")) { 
     $.post(this.href); 
    } 
    return false; 
}); 

此外,一定要檢查出jQueryUI的的確認情態動詞:http://jqueryui.com/demos/dialog/#modal-confirmation