Do you want to display the Yes and No buttons instead of OK and Cancel in confirmation?

Possible duplicate:
how to create yes / no / cancel field in javascript instead of ok / cancel?

In the confirmation message box, how can I change the buttons to say β€œYes” and β€œNo” instead of β€œOK” and β€œCancel”? Is there a way to do this using jQuery / Javascript? Thanks in advance for any help.

+8
javascript jquery
Jun 22 2018-11-21T00:
source share
6 answers

If you switch to the JQuery UI dialog box, you can initialize an array of buttons with the corresponding names, for example:

$("#id").dialog({ buttons: { "Yes": function() {}, "No": function() {} } }); 
+12
Jun 22 '11 at 20:17
source share

Create your own flag to confirm:

 <div id="confirmBox"> <div class="message"></div> <span class="yes">Yes</span> <span class="no">No</span> </div> 

Create your own confirm() method:

 function doConfirm(msg, yesFn, noFn) { var confirmBox = $("#confirmBox"); confirmBox.find(".message").text(msg); confirmBox.find(".yes,.no").unbind().click(function() { confirmBox.hide(); }); confirmBox.find(".yes").click(yesFn); confirmBox.find(".no").click(noFn); confirmBox.show(); } 

Call it by your code:

 doConfirm("Are you sure?", function yes() { form.submit(); }, function no() { // do nothing }); 

You need to add CSS to the style and place the confirmation box correctly.

Working demo: jsfiddle.net/Xtreu

+9
Jun 22 '11 at 20:29
source share

No, it is not possible to change the contents of the buttons in the dialog box displayed by the confirm function. However, you can use Javascript to create a dialog box similar to it. This page lists several ways to accomplish this.

+1
Jun 22 '11 at 20:16
source share

There is a warning jquery plugin

 $.alerts.okButton = ' Yes '; $.alerts.cancelButton = ' No '; 
+1
Jun 22 '11 at 20:20
source share

As far as I know, changing the contents of buttons is impossible, at least not easy. It's pretty easy for you to create your own alert window using the jQuery UI, although

+1
Jun 22 '11 at 20:25
source share

An example using the JQuery UI dialog box: http://jsfiddle.net/JAAulde/qqkGA/ , as well as the native UI demo application: http://jqueryui.com/demos/dialog/#modal-confirmation

+1
Jun 22 '11 at 20:28
source share



All Articles