用jquery确认替换JavaScript确认

编程入门 行业动态 更新时间:2024-10-08 22:54:18
本文介绍了用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扩展,警报的jQuery UI替换 相关问题: 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确认

本文发布于:2023-11-27 21:33:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jquery   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!