我有以下MySQL用于删除按钮。
DELETE FROM mytable
WHERE id = $id
我想添加一个jquery模式来确认继续。 “你确定要删除吗?是|否”
如果单击YES,则执行删除,如果为NO,则退出模态并返回页面。
每个锚中的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>
...
最好的方法是什么?
答案 0 :(得分: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 :(得分: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