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>
...

最好的方法是什么?

4

2 回答 2

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”所在的数据......

于 2009-12-05T11:29:53.403 回答
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 进行删除:

// 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

于 2009-12-05T11:48:40.830 回答