如何在Javascript中创建TRULY模态警报/确认? [英] How to create TRULY modal alerts/confirms in Javascript?

查看:84
本文介绍了如何在Javascript中创建TRULY模态警报/确认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在筛选 prompt() confirm()替换JavaScript。我需要创建一些有三个或更多选项的confirm()和alert()。我想使用我已经使用的Lightbox类。但是,我找到的替换都没有直接返回操作的结果,如confirm()和prompt()可以:

I am sifting through prompt() and confirm() replacements for JavaScript. I need to create a couple of confirm()s and alert()s that have three or more options. I would like to use the Lightbox class that I am using already. However, none of the replacements I have found can return the result of the operation directly like confirm() and prompt() can:

success = confirm("Success yes / no?");
if (success == true)
 ......

可以写一个替换,以便它以相同的方式运行,即它打开一个对话框,等待用户输入并返回点击了哪些按钮?或者这是不可能的(这就是我现在所怀疑的)你必须通过将动作附加到是/否/无论按钮本身来解决它?

can a replacement be written so that it behaves in the same manner, i.e. that it opens a dialog, waits for user input and returns which buttons have been clicked? Or is this impossible to do (That's what I'm suspecting right now) and you have to work around it by attaching the actions to the "yes / no / whatever" buttons themselves?


编辑:毕竟我决定不接受Josh的回答。它是完全有用的,但它没有回答这个问题 - 有没有办法在Javascript中拥有真正的模态对话框?似乎没有。

I have decided to unaccept Josh's answer after all. It is totally helpful, but it doesn't answer the question - is there a way to have truly modal dialogs in Javascript? There doesn't seem to be.


推荐答案

大多数具有UI组件的JavaScript框架都有一些一种将提供回调的对话框。查看jQuery UI,例如: http://jqueryui.com/demos/dialog/

Most JavaScript frameworks that have UI components have some kind of dialog that will provide callbacks. Check out jQuery UI, for example: http://jqueryui.com/demos/dialog/

我在多个项目中使用它来完成您所描述的内容。

I've used it in multiple projects to do exactly what you're describing.

编辑:我希望建议一个解决方法。遗憾的是,JavaScript不包括覆盖默认的基于浏览器的Alert(),Confirm()或Prompt()对话框的方法和添加其他按钮或选项。

I was hoping to suggest a workaround. Unfortunately JavaScript does not include methods to override and add additional buttons or options to the default browser-based Alert(), Confirm(), or Prompt() dialogs.

这篇关于如何在Javascript中创建TRULY模态警报/确认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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