Javascript - rename confirm() buttons

牧云@^-^@ 提交于 2019-11-30 08:55:39

问题


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


回答1:


http://dev.w3.org/html5/spec-preview/user-prompts.html#simple-dialogs

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

The browser must display an OK/Cancel prompt to comply with HTML5.




回答2:


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.




回答3:


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");
  });
});



回答4:


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



来源:https://stackoverflow.com/questions/22885897/javascript-rename-confirm-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!