如何结合两个jQuery函数? [英] How to combine two jQuery functions?

查看:94
本文介绍了如何结合两个jQuery函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个功能(可以在 http://nadiana.com/jquery-confirm-plugin <中找到):

The first function (can be found at 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?<br>',
    buttons: {
    separator: ' - '
    }
}
);

基本上会有是/否"问题,如果您回答是",则会继续进行操作.

Basically there is Yes/No question, and if you answer Yes, it proceed further.

第二功能:

$(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: "<?php echo site_url('gallery/delete_image') ?>",
            type: "POST",
            data: string,
            cache: false,
            success: function(){
                commentContainer.slideUp('slow', function() {$(this).remove();});
                $('#load').fadeOut();
            }   
        });
        return false;
    });
});

此功能用于删除图像. 如何结合这两个功能?首先,我想问一个问题,然后单击是"以继续删除.

This function is for deleting images. How can I combine this two functions? First I want question to be asked, and if Yes is clicked to proceed with deleting.

推荐答案

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

According to the documentation you linked to, you simply use the same selector for both your action and your confirm:

$(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: "<?php echo site_url('gallery/delete_image') ?>",
            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?<br>',
        buttons: {
        separator: ' - '
        }
    });
});

这篇关于如何结合两个jQuery函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆