Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

javascript - What's the best way to write my own confirm in js?

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 is supposed to show the modal, wait until either yes or no button was pressed and then return true or false.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...