问题描述
我正在筛选 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?
推荐答案
大多数具有UI组件的JavaScript框架都有一些一种将提供回调的对话框。查看jQuery UI,例如:
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模态警报/确认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!