如何结合两个jQuery函数?

第一个function(可在http://nadiana.com/jquery-confirm-plugin找到):

$('#confirm').confirm( { msg: 'You are about to delete gallery and all images related to that gallery. Are you sure?
', buttons: { separator: ' - ' } } );

基本上是有/没有问题,如果你回答是,它继续进行。

第二function:

 $(document).ready(function() { $('#load').hide(); }); $(function() { $(".delete").click(function() { $('#load').fadeIn(); var commentContainer = $(this).parent(); var id = $(this).attr("id"); var string = 'id='+ id ; $.ajax({ url: "", type: "POST", data: string, cache: false, success: function(){ commentContainer.slideUp('slow', function() {$(this).remove();}); $('#load').fadeOut(); } }); return false; }); }); 

此function用于删除图像。 我该如何结合这两个function? 首先,我想要询问问题,如果单击是,则继续删除。

根据您链接的文档,您只需对您的操作和确认使用相同的选择器:

 $(document).ready(function() { $('#load').hide(); $(".delete").click(function() { $('#load').fadeIn(); var commentContainer = $(this).parent(); var id = $(this).attr("id"); var string = 'id='+ id ; $.ajax({ url: "", type: "POST", data: string, cache: false, success: function(){ commentContainer.slideUp('slow', function() {$(this).remove();}); $('#load').fadeOut(); } }); return false; }); $('.delete').confirm( { msg: 'You are about to delete gallery and all images related to that gallery. Are you sure?
', buttons: { separator: ' - ' } }); });

这是一个与你选择的插件相关的问题,但正如你可以在插件手册中看到的那样,它只是将两个事件添加到同一个元素中,然后插件完成剩下的工作。

从网站:

简单地说,它保存了绑定到元素的所有事件处理程序的副本,取消绑定它们并绑定它们自己。 当用户触发操作时,将显示确认对话框。 如果用户选择继续执行操作,则会再次重新绑定处理程序并触发事件。 如果用户选择取消操作,则对话框将消失。

所以你需要做的是:

 $('#delete').click(function(){ ... }); $('#delete').confirm(); 

当然,您可以根据需要进行扩展。