简体   繁体   English

停止并稍后在jquery ui模式对话框中说服javascript事件

[英]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. event.run()在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. 如果暂停,它将阻止整个DOM。 Try: 尝试:

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

When using jQuery its possible to set additional event parameters what I did: 当使用jQuery时,可以设置其他事件参数:

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. 第一次单击show_dialog是未定义的,并显示模式对话框。 Clicking on Yes in modal dialog triggers the event.type (click) with the additional parameter true for show_dialog. 在模式对话框中单击“是”会触发event.type(单击),并为show_dialog附加参数true。 http://api.jquery.com/trigger/#trigger-eventType-extraParameters http://api.jquery.com/trigger/#trigger-eventType-extraParameters

It was not possible to that.trigger(event, [true]); that.trigger(event, [true]);不可能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. 您需要做的.trigger()一个新事件。

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? 如果您click将消失怎么办?
If it just fires off a different function, why not just call that function instead of attempting event.run() ? 如果它只是触发了另一个函数,为什么不调用该函数而不是尝试event.run()呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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