在js中编写自己的确认的最佳方法是什么? [英] What's the best way to write my own confirm in js?

查看:63
本文介绍了在js中编写自己的确认的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用bootstrap模式为我自己的确认对话框设置皮肤而不必连接事件而不使用任何库,除了angular或jquery。

I want to skin my own confirmation dialog using bootstrap modal without having to hook up events and without resorting to any library, except angular or jquery.

基本上,我希望能够调用类似的东西:

Basically, I want to be able to call something like:

if (myConfirm("text")) {
    // handle yes
} else {
    // handle no
};

myConfirm应显示模态,等到是或否按下按钮然后返回true或者是假的。

myConfirm is supposed to show the modal, wait until either yes or no button was pressed and then return true or false.

最好的方法是什么?
我对任何IE问题都不感兴趣。

What's the best way to do this? I am not concerned at all about any IE issues.

推荐答案

阻止功能的最佳选择是旧的 window.showModalDialog 方法(具有优秀的 IE支持,顺便说一句。 但是你不应使用

Your best bet for a blocking function is the old window.showModalDialog method (which has excellent IE support, btw). But you should not use it.

将其设为基于事件的。特别是出于学习目的。没有事件,您将无法获得引导模式。如果你想要更好的抽象,请从你的函数中返回一个Promise。

Make it event-based. Especially when for learning purposes. You won't get the bootstrap modal without events. If you want a nicer abstraction, return a Promise from your function.

这篇关于在js中编写自己的确认的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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