更改 JavaScript 警报按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6655945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:25:51  来源:igfitidea点击:

Changing JavaScript alert buttons

javascriptbutton

提问by penny

How do you change the words on the buttons in a javascript alert? I am new so the simplest way possible would be greatly appreciated.

您如何更改 javascript 警报中按钮上的文字?我是新来的,所以最简单的方法将不胜感激。

回答by SLaks

You can't.

你不能。

Instead, you can create a fake dialog in the DOM, using jQuery UI Dialog.

相反,您可以使用jQuery UI Dialog在 DOM 中创建一个假对话框。

回答by beardhatcode

not possible, the browser sets that

不可能,浏览器设置

what you could do is make a fake alert from elements,

你可以做的是从元素中发出假警报,

回答by ShankarSangoli

You can overriede window.alert and have your own implemenation of it.

您可以覆盖 window.alert 并对其进行自己的实现。

window.alert = function(msg, options){
     //Create the alert dialog box here using the default options and show the message.
}

You dont have to change your code in the application to use it.

您不必更改应用程序中的代码即可使用它。

回答by ShankarSangoli

Try something like this

尝试这样的事情

    function CustomAlert(msg){
var customAlert = $("#customAlert");
      if(!customAlert.length){
        customAlert = $(document.body).append('<div id="customAlert"><div class="message">Msg></div><div><input class="button"     type="button" value="Ok" /></div></div>').hide();
}
customAlert.find("message").html(msg);

//Code to center the customAlert into view port along with faded background will go here

customAlert.find("input.button").unbind("click").click(function(){ 
 //Hide the customAlert goes here
 customAlert.hide();
});

    }