Javascript 自定义确认“是”或“否”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6937761/
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
Javascript Customize Confirm with "Yes" or "No"
提问by testndtv
How do I have a Javascript confirm() box with "Yes" or "No" instead of the default "Ok" or "Cancel" ?
我如何使用“是”或“否”而不是默认的“确定”或“取消”的 Javascript 确认()框?
回答by cillierscharl
The javascript confirm dialog cannot be customized.
无法自定义 javascript 确认对话框。
If you require dialog customization I would suggest looking at JQuery UI - Dialog
如果您需要自定义对话框,我建议您查看JQuery UI - Dialog
回答by JMax
You cannot do it with standard javascript.
你不能用标准的 javascript 做到这一点。
You have this workaround for IE only(source):
您只有 IE 的此解决方法(来源):
<script language=javascript>
/*@cc_on @*/
/*@if (@_win32 && @_jscript_version>=5)
function window.confirm(str)
{
execScript('n = msgbox("'+str+'","4132")', "vbscript");
return(n == 6);
}
@end @*/
var r = confirm("Can you do it?");
alert(r);
</script>
Or, you can use custom dialog from jquery ui
或者,您可以使用jquery ui 中的自定义对话框
回答by Nicola Peluchetti
To put it simply i think you can't. There are a lot of answers about that on stack overflow, for example this one : custom choices in javascript confirm dialogthat states it. If you want to do it, you have to use your own dialogs like those of jquery ui
简单地说,我认为你不能。有很多关于堆栈溢出的答案,例如这个:javascript 确认对话框中的自定义选择说明它。如果你想这样做,你必须使用你自己的对话框,比如 jquery ui
回答by Raphael Parent
Today, you can do it simply with javascript. There's is a simple js library called notiejsthat has a confirm option.
今天,您可以简单地使用 javascript 来完成。有一个名为notiejs的简单 js 库,它有一个确认选项。
With a simple line
用简单的线条
notie.confirm('Title text', 'Yes button text', 'No button text', yes_callback)
you can have a custom confirm box. (Maybe the style or the interaction won't fit your use case but I'm just pointing out that it is possible).
你可以有一个自定义的确认框。(也许风格或交互不适合您的用例,但我只是指出这是可能的)。