确认之前,Alertify对话框消失了 [英] Alertify dialog disappeared before confirming

查看:131
本文介绍了确认之前,Alertify对话框消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在写一些代码,遇到了这样的问题:

I was just writing some code and I met a problem like this:

alertify.dialog("confirm").set(
{
    'labels':
    {
        ok: 'Personal',
        cancel: 'Share'
    },
    'message': 'Select target:',
    'onok': function()
    {
        alertify.confirm($("#dir_select_user").get(0), function()
        {
            var i = $("#dir_select_user .dir_selector").val();
            t.find(".move_des").val(i);
            t.find(".move_verify").val("1");
            t.submit();
        }).set('labels',
        {
            ok: alertify.defaults.glossary.ok,
            cancel: alertify.defaults.glossary.cancel
        });
    },
    'oncancel': function()
    {
        alertify.confirm($("#dir_select_share").get(0), function()
        {
            var i = $("#dir_select_share .dir_selector").val();
            t.find(".move_des").val(i);
            t.find(".move_verify").val("1");
            t.submit();
        }).set('labels',
        {
            ok: alertify.defaults.glossary.ok,
            cancel: alertify.defaults.glossary.cancel
        });
    }
})   }).show();

我使用来自 http://alertifyjs.com alertifyjs库(不是来自

I use the alertifyjs library from http://alertifyjs.com (not from http://fabien-d.github.io/alertify.js/).

如果尝试使用此代码,则会发现在选择personalshare后,"onok"和"oncancel"对话框迅速消失.

If you try this code, you'll find that 'onok' and 'oncancel' dialogs quickly disappear after choosing personal or share.

这是什么问题?我该怎么解决?

What's the problem here? How can I solve it?

推荐答案

问题的根源是您试图在关闭对话框时再次显示相同的对话框.默认的AlertifyJS对话框均为单例(始终为一个实例).

The source of your problem is that you are trying to show the same dialog again while its being closed. The default AlertifyJS dialogs are all singletons (one instance at all times).

您有2种解决方案:

  1. 显示第二个确认的延迟,直到第一个确认实际关闭为止.

  1. Delay showing the second confirm until the first confirm is actually closed.

alertify.confirm("confirm ? ", 
    function onOk() {
        //delay showing the confirm again 
        //till the first confirm is actually closed.
        setTimeout(function () {
            alertify.confirm("confirm another time ?");
        }, 100);
    },
    function onCancel() {
        //no delay, this will fail to show!
        alertify.confirm("this will not be shown!");
    }
);

  • 创建您自己的瞬态(多实例)确认,只需从现有实例中继承即可.

  • Create your own transient (multi-instance) confirm, simply inherit from the existing one.

    // transient (multi-instance)
    alertify.dialog('myConfirm', function factory(){ return {};},true,'confirm');
    alertify.myConfirm("confirm ? ", function(){
        alertify.myConfirm("confirm another time ?");
    });
    

    注意:请注意这一点,因为每次调用瞬态对话框都会创建一个新实例,因此您可以保存对已启动实例的引用并重新使用它们!

    Note: be careful with this, as each call to a transient dialog will create a new instance, you may save references to launched instances and re-use them!

    请参见演示此处.

    这篇关于确认之前,Alertify对话框消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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