如何添加警告模式删除
问题描述:
我有以下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>
...
什么是做这种方式吗?
答
< 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”是数据...
答
一种办法是给删除链接的一类,然后你可以做这样的事情:如果你
// 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