带有.click事件的实时点击绑定。防止递归

时间:2011-07-11 16:01:35

标签: jquery recursion

我有一个使用.live的jquery事件绑定,它将fancybox添加到click事件,然后调用click事件以使用fancybox。有没有办法防止递归:

$('.remindMe').live('click', function (e) {
        $(this).fancybox({
            'padding': 0,
            'width': '235',
            'height': '375',
            'autoDimensions': false,
            'hideOnOverlayClick': false,
            'onComplete': function () {
                $('div.formControls .bigpinkbutton').click(function () {
                    $('div.reminder-header h2').text("Reminder Sent");
                    $('div.reminder-header h2').css('border-bottom', 'none');
                    $('div.reminder-header h2').css('margin-bottom', '0');
                    $('div.reminder-header h2').css('padding-bottom', '15px');
                    $('div.reminder-header span').fadeOut();
                    $('div.reminder-body p').first().html("<strong>Thank you.</strong> This notice is to confirm your product reminder email has been sent.");
                    $('div.reminder-body div.formControls').fadeOut();
                    var id = $(this).parent().parent().parent().parent().attr("id").replace("remindme", "");
                    var email = $(this).parent().find("#reminder_email").val();
                    $.post(baseURL + "SendReminder", { "email": email, "productID": id });
                });
            }
        }).trigger("click");
);

非常感谢。

3 个答案:

答案 0 :(得分:3)

试试这个

$('.remindMe').live('click', function (e) {

        $(this).fancybox({
            'padding': 0,
            'width': '235',
            'height': '375',
            'autoDimensions': false,
            'hideOnOverlayClick': false,
            'onComplete': function () {
                $('div.formControls .bigpinkbutton').click(function () {
                    $('div.reminder-header h2').text("Reminder Sent");
                    $('div.reminder-header h2').css('border-bottom', 'none');
                    $('div.reminder-header h2').css('margin-bottom', '0');
                    $('div.reminder-header h2').css('padding-bottom', '15px');
                    $('div.reminder-header span').fadeOut();
                    $('div.reminder-body p').first().html("<strong>Thank you.</strong> This notice is to confirm your product reminder email has been sent.");
                    $('div.reminder-body div.formControls').fadeOut();
                    var id = $(this).parent().parent().parent().parent().attr("id").replace("remindme", "");
                    var email = $(this).parent().find("#reminder_email").val();
                    $.post(baseURL + "SendReminder", { "email": email, "productID": id });
                });
            }
        }).triggerHandler("click");
);

答案 1 :(得分:1)

尝试:

$('.remindMe:not(.bigpinkbutton)').live('click', function (e) {

注意:not()条款。

答案 2 :(得分:0)

使用手动调用语法。

$('.remindMe').live('click', function (e) {
    $.fancybox({
        'href': this.href,
        'padding': 0,
        'width': '235',
        'height': '375',
        'autoDimensions': false,
        'hideOnOverlayClick': false,
        'onComplete': function () {
            $('div.formControls .bigpinkbutton').click(function () {
                $('div.reminder-header h2').text("Reminder Sent");
                $('div.reminder-header h2').css('border-bottom', 'none');
                $('div.reminder-header h2').css('margin-bottom', '0');
                $('div.reminder-header h2').css('padding-bottom', '15px');
                $('div.reminder-header span').fadeOut();
                $('div.reminder-body p').first().html("<strong>Thank you.</strong> This notice is to confirm your product reminder email has been sent.");
                $('div.reminder-body div.formControls').fadeOut();
                var id = $(this).parent().parent().parent().parent().attr("id").replace("remindme", "");
                var email = $(this).parent().find("#reminder_email").val();
                $.post(baseURL + "SendReminder", { "email": email, "productID": id });
            });
        }
    });
);