JQuery 确认对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12617084/
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
JQuery confirm dialog
提问by MayoMan
Possible Duplicate:
Yes or No confirm box using jQuery
可能的重复:
使用 jQuery 是或否确认框
I see a lot of examples here about replacements for jQuerys standard confirm dialog but don't understand any of them.
我在这里看到很多关于替换 jQuery 标准确认对话框的示例,但不了解其中任何一个。
If I want to pop-up a confirm dialog using jQuery or jQueryUI. How can i do it and retrieve what button the user clicked ?
如果我想使用 jQuery 或 jQueryUI 弹出一个确认对话框。我该怎么做并检索用户单击的按钮?
Surely there must be a simple way to set up a confirm dialog like an alert("Something!");
command.
当然,必须有一种简单的方法来设置像alert("Something!");
命令一样的确认对话框。
Add two buttons to it and set a call back function on yes
or no
?
为其添加两个按钮并在yes
或上设置回调功能no
?
回答by MaVRoSCy
Try this one
试试这个
$('<div></div>').appendTo('body')
.html('<div><h6>Yes or No?</h6></div>')
.dialog({
modal: true, title: 'message', zIndex: 10000, autoOpen: true,
width: 'auto', resizable: false,
buttons: {
Yes: function () {
doFunctionForYes();
$(this).dialog("close");
},
No: function () {
doFunctionForNo();
$(this).dialog("close");
}
},
close: function (event, ui) {
$(this).remove();
}
});
回答by LeftyX
You can use jQuery UI and do something like this
您可以使用 jQuery UI 并执行以下操作
Html:
网址:
<button id="callConfirm">Confirm!</button>
<div id="dialog" title="Confirmation Required">
? Are you sure about this?
</div>?
Javascript:
Javascript:
$("#dialog").dialog({
autoOpen: false,
modal: true,
buttons : {
"Confirm" : function() {
alert("You have confirmed!");
},
"Cancel" : function() {
$(this).dialog("close");
}
}
});
$("#callConfirm").on("click", function(e) {
e.preventDefault();
$("#dialog").dialog("open");
});
?
?
回答by indra
Have you tried using the official JQueryUI implementation(not jQuery only) : ?
您是否尝试过使用官方的 JQueryUI 实现(不仅仅是 jQuery):?