jQuery技术:如何结合两个jQuery函数?

第一个function(可在https://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(); 

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

      以上就是jQuery教程分享如何结合两个jQuery函数?相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/561243.html

      (0)
      上一篇 2021年2月4日
      下一篇 2021年2月4日

      精彩推荐