简体   繁体   中英

stop and later persue javascript event in jquery ui modal dialog

I want to stop an event show a modal dialog and if the user presses yes persue this event. event.run() brings an error in firefox.

jQuery(element).click(function(event) {
    event.preventDefault();
    dialog.dialog({
        buttons: {
            'Ja': function() {
                event.run();
            },
            'Nein': function() {
                jQuery(this).dialog('close');
            }

        }
    }).dialog('open');
});

Thanks to a friend and hashbrown I managed to solve this problem. An event cannot be paused and persued. If it is paused it will block the whole DOM. Try:

jQuery(link).click(function(){while(true)});

When using jQuery its possible to set additional event parameters what I did:

jQuery(element).click(function(event, show_dialog) {
    var that = jQuery(this);
    if(!show_dialog) {
        dialog.dialog({
            buttons: {
                'Yes': function() {
                    that.trigger(event.type, [true]);
                },
                'No': function() {
                    jQuery(this).dialog('close');
                }

            }
        }).dialog('open');
        return false;
    } else {
        dialog.dialog('close');
        return true;
    }
});

First click show_dialog is undefined and modal dialog is shown. Clicking on Yes in modal dialog triggers the event.type (click) with the additional parameter true for show_dialog. http://api.jquery.com/trigger/#trigger-eventType-extraParameters

It was not possible to that.trigger(event, [true]); . I think cause events default action was prevented before.

That is because immediately after creating the popup the function returns and the event expires.
What you'll have to do is .trigger() a new event.

Note: set some sort of global variable to ignore this second event firing in your anonymous function (infinite loop problem).

Can I ask why you want to do this; what would click go off and do if you let it?
If it just fires off a different function, why not just call that function instead of attempting event.run() ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM