如何添加 Jquery 确认模式
我试图使用 jquery 从数据库中删除数据,以下脚本帮助我做到了这一点。现在我想在最终删除它之前显示一个 jquery 确认模式(是:否)。我浏览了一些教程来学习如何做到这一点,但我无法让这些为我工作,
请告诉我如何添加确认模式。
谢谢
<script>
$(function(){ // added
$('a.delete').click(function(){
var a_href = $(this).attr('href');
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>batchlist/delete",
data: "id="+a_href,
success: function(server_response){
if(server_response == '1')
{ alert('MSG');} else {$("#trid_"+a_href).hide('slow'); }
}
}); //$.ajax ends here
return false
});//.click function ends here
}); // function ends here
</script
这是我的删除锚点
<a href="<?php echo $row['studentid']; ?>" title="Delete" class="delete" ><img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" /></a>
I was trying to delete a data from database using jquery and the following script helped me to do so. Now I want to show a jquery confirmation modal(YES: NO) before it finally goes for deleting it. I went through some tutorials to learn how to do that but I couldn't make those work for me
Please kindly show me how to add the confirmation modal.
Thanks
<script>
$(function(){ // added
$('a.delete').click(function(){
var a_href = $(this).attr('href');
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>batchlist/delete",
data: "id="+a_href,
success: function(server_response){
if(server_response == '1')
{ alert('MSG');} else {$("#trid_"+a_href).hide('slow'); }
}
}); //$.ajax ends here
return false
});//.click function ends here
}); // function ends here
</script
This is my delete anchor
<a href="<?php echo $row['studentid']; ?>" title="Delete" class="delete" ><img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" /></a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不需要 jQuery 来做到这一点。 Javascript 会很可爱地做到这一点:
简单:)
you don't need jQuery to do this. Javascript will do this just lovelyly:
Simple :)
最简单的方法是使用基本的 javascript。
在 ajax 调用之前,将其放入
So 如果他们拒绝,ajax 就不会打扰。
The simplest way to do this is with basic javascript.
Right before the ajax call, put this
So if they decline, it just doesn't bother with the ajax.
我发现使用 jquery 小部件进行模式对话框并处理删除/取消按钮很方便。
用法非常简单,您只需创建用于确认对话框的 div:
并将小部件应用于此 div,传递应触发确认对话框的元素显示:
也是为了方便起见,我在显示模式对话框的按钮上使用数据属性来修改文本并传递值对于帖子删除操作。
仅此而已)
I find it convinient to use jquery widget for modal dialog, and handle delete/cancel buttons.
usage is really simple, you just create div for confirmation dialog:
and apply widget to this div, passing the elements that should trigger confirmation dialog show:
also for convinience i use data- attributes on buttons that show modal dialog to modify text and pass value for post to delete action.
and thats all )