开发者

live click binding with a .click event inside. Preventing recursion

开发者 https://www.devze.com 2023-03-19 23:50 出处:网络
I have a jquery event binding using .live that adds fancybox to the click event, then calls the click event to use fancybox.Is there a way to prevent recursion here:

I have a jquery event binding using .live that adds fancybox to the click event, then calls the click event to use fancybox. Is there a way to prevent recursion here:

$('.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");
);

Thanks very much.


Try this

$('.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");
);


Try:

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

Notice :not() clause.


Use the manual call syntax.

$('.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 });
            });
        }
    });
);
0

精彩评论

暂无评论...
验证码 换一张
取 消