Javascript - rename confirm() buttons

后端 未结 4 753
一个人的身影
一个人的身影 2020-12-18 20:13

By default, there are two buttons:\"ok\" and \"cancel\" in confirm().
Is there a way to rename them?

相关标签:
4条回答
  • 2020-12-18 20:55

    https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-confirm

    According to the standard that defines confirm(), there is no way to specify custom button labels.

    The browser must display a "positive or negative" prompt (e.g. OK/Cancel) to comply with HTML5.

    0 讨论(0)
  • 2020-12-18 20:58

    You can't change the buttons of the default confirm popup. A workaround is to recreate the whole popup in JavaScript. One such workaround is http://jqueryui.com/dialog/#modal-confirmation

    0 讨论(0)
  • 2020-12-18 21:01

    No, there isn't. Confirm only takes one argument and that is the message itself.

    http://dev.w3.org/html5/spec-preview/user-prompts.html#dom-confirm

    Keep in mind these dialogs are modal and blocking, which means once they are executed you lose control over the program flow. You'd be on a safer route if you implemented your dialogs using a javascript library of your choice or building yours.

    0 讨论(0)
  • 2020-12-18 21:03

    There is a way IF you use a custom modal to confirm. Something like that:

    $(document).ready(function() {
      $('#btn').on('click', function () {
        myApp.confirm('Are you sure?', 'Title', function () {
          $('.btn-no').text("No");
          $('.btn-yes').text("Yes");
      });
    });
    
    0 讨论(0)
提交回复
热议问题