最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

'Yes', 'No', and Cancel with JavaScript confirm function - Stack Overflow

programmeradmin1浏览0评论

I am familiar with the basic JavaScript confirm function. I want to take one step further: instead of having a message box pop up with the options of "OK" and "Cancel", I would like to add three options and change the dialog so that the three choices read "Confirm", "Deny", and "cancel". A "Confirm" or "Deny" choice would each call a different function. Any suggestions on how to do this?

I am not using JQuery or any other library, and i really don't want to use any if I can help it, as it's just this one function. Any help would be appreciated.

I am familiar with the basic JavaScript confirm function. I want to take one step further: instead of having a message box pop up with the options of "OK" and "Cancel", I would like to add three options and change the dialog so that the three choices read "Confirm", "Deny", and "cancel". A "Confirm" or "Deny" choice would each call a different function. Any suggestions on how to do this?

I am not using JQuery or any other library, and i really don't want to use any if I can help it, as it's just this one function. Any help would be appreciated.

Share Improve this question asked Jul 28, 2011 at 17:59 AnonymousAnonymous 211 silver badge2 bronze badges 2
  • Dup: stackoverflow./questions/1800033/… – Ray Toal Commented Jul 28, 2011 at 18:01
  • Possible duplicate of how to show confirmation alert with three buttons 'Yes' 'No' and 'Cancel' as it shows in MS Word – David Millar Commented Mar 8, 2017 at 21:43
Add a ment  | 

2 Answers 2

Reset to default 2

You will want to look into making a custom dialog from a div, and assign click events to the buttons. You can't modify the browser's standard dialogs without using VBScript which is IE only.

The fact that you don't want to use JQuery is quite silly. It's 31k and the best thing to ever happen to JavaScript.

If you want to avoid JQueryUI, you can create a dialog yourself very easily. Here's a tutorial to get you started: http://www.queness./post/1696/create-a-beautiful-looking-custom-dialog-box-with-jquery-and-css3

AFAIK, you cannot change the button prompt strings with just using pure JS. It has to be 'OK' and 'Cancel'.

发布评论

评论列表(0)

  1. 暂无评论