用jquery确认替换JavaScript确认 [英] Replace javascript confirm by jquery confirm

查看:102
本文介绍了用jquery确认替换JavaScript确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码通过jquery ui对话框使用默认的javascript确认.

I use the following code to use default javascript confirm by jquery ui dialogue.

jQuery.extend({
    confirm: function(message, title, okAction) {
        jQuery("<div></div>").dialog({
            // Remove the closing 'X' from the dialog
            open: function(event, ui) { jQuery(".ui-dialog-titlebar-close").hide(); }, 
            buttons: {
                "Ok": function() {
                    jQuery(this).dialog("close");
                    return true;
                },
                "Cancel": function() {
                    jQuery(this).dialog("close");
                    return false;
                }
            },
            close: function(event, ui) { jQuery(this).remove(); },
            resizable: false,
            title: title,
            modal: true
        }).text(message);
    }
});

jQuery.confirm(
        "LogOut",
        "Do you want to log out",
        function() { 
        });

现在,我需要在注销操作中使用相同的代码.这样我就可以替换代码中的javascript确认了.

Now I need to use this same code in a log out action. So that I can replace the javascript confirm in the code.

<a class="homeImage" onclick="return confirm('Do you want to logout?');" href="/future/myhome/head?$event=logout">LOG OUT</a>

我现在面临的问题是,当我用另一个函数替换确认并等待其返回值做出决定时,对话框不会将值返回给变量.这两个函数是同时执行的(它显示警报,但也将其定向到href目标).该方法是否可以通过任何方式返回true或false值,然后继续执行href目标.

The problem I am facing now is, when I replace the confirm with another function and wait for its return value to make the decision, the dialogue box doesn't return the value to a variable. These two functions are executed simultaniously(its showing the alert, but it also get directed to the href target). Is there any way that the method can return a true or false value and hence proceed to the href target.

参考: jQuery扩展 js覆盖确认

reference: jQuery Extend,jQuery UI Replacement for alert
related question : js override confirm

推荐答案

问题是默认的confirm对话框是syncnus,并阻止了整个浏览器UI. jQuery对话框是异步的,不会阻塞UI(因为它需要呈现).

The problem is that default confirm dialog is synchronus and block the whole browser UI. JQuery dialog is asynchronous and does not block UI (because it needs it to render).

因此,下面是您的问题的答案.您需要更改:

So the answer to your problem is following. You need to change:

         buttons: {
            "Ok": function() {
                window.location = "/future/myhome/head?$event=logout"
            },

 <a class="homeImage" onclick="return jQuery.confirm('Do you want to logout?');return false;" href="/future/myhome/head?$event=logout">LOG OUT</a>

这篇关于用jquery确认替换JavaScript确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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