Javascript 在确认框中显示是和否按钮而不是确定和取消?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6445946/
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
Display Yes and No buttons instead of OK and Cancel in Confirm box?
提问by user300485
Possible Duplicate:
how to create yes/no/cancel box in javascript instead of ok/cancel?
In a Confirm message box, how can I change the buttons to say "Yes" and "No" instead of "OK" and "Cancel"? Is there some way to accomplish this using jQuery/Javascript? Thanks in advance for any help.
在确认消息框中,如何将按钮更改为“是”和“否”而不是“确定”和“取消”?有什么方法可以使用 jQuery/Javascript 来完成这个任务吗?在此先感谢您的帮助。
回答by Richard B
If you switch to the jQuery UI Dialog box, you can initialize the buttons array with the appropriate names like:
如果切换到 jQuery UI 对话框,则可以使用适当的名称初始化按钮数组,例如:
$("#id").dialog({
buttons: {
"Yes": function() {},
"No": function() {}
}
});
回答by gilly3
Create your own confirm box:
创建您自己的确认框:
<div id="confirmBox">
<div class="message"></div>
<span class="yes">Yes</span>
<span class="no">No</span>
</div>
Create your own confirm()
method:
创建自己的confirm()
方法:
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'll need to add CSS to style and position your confirm box appropriately.
您需要添加 CSS 以适当地设置样式和定位您的确认框。
Working demo: jsfiddle.net/Xtreu
工作演示:jsfiddle.net/Xtreu
回答by Donut
No, it is not possible to change the content of the buttons in the dialog displayed by the confirm
function. You can use Javascript to create a dialog that looks similar.
不可以,无法更改该confirm
功能显示的对话框中按钮的内容。您可以使用 Javascript 创建一个看起来相似的对话框。
回答by Mike Vormwald
回答by riku
As far as I know, it's not possible to change the content of the buttons, at least not easily. It's fairly easy to have your own custom alert box using JQuery UI though
回答by JAAulde
An example using jQuery UI dialog: http://jsfiddle.net/JAAulde/qqkGA/as well as UI's own demo: http://jqueryui.com/demos/dialog/#modal-confirmation
使用 jQuery UI 对话框的示例:http: //jsfiddle.net/JAAulde/qqkGA/以及 UI 自己的演示:http: //jqueryui.com/demos/dialog/#modal-confirmation