我只能找到提供OK / Cancel按钮的函数confirm()
。有没有办法给出是/否按钮?
答案 0 :(得分:8)
答案 1 :(得分:2)
没有
相反,您可以使用浏览器模式弹出窗口。
答案 2 :(得分:2)
与上述其他人一样,您使用confirm()
时仍然无法使用确定/取消。
我想推荐这个jQuery插件:jqModal。我已经在最近的3个项目中使用它,并且它对每个项目都很有效。具体来看看这个例子:
6)。 FUN!覆盖 - a。查看(警报),b。查看(确认)现在是时候了 显示jqModal的实际用途 - 覆盖标准alert()和 确认对话框!注意;因为 单线程性质的javascript, 必须传递confirm()函数 回调 - 它不会返回 真/假。
答案 3 :(得分:1)
不,但有一些JavaScript库可以为您完成此任务。仅作为示例,Ext JS可用于创建message box dialog。
答案 4 :(得分:1)
对于这类事,我是jQuery UI Dialog的粉丝。这是一个样本......
<script>
$(function() {
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Yes": function() {
$( this ).dialog( "close" );
alert("You chose Yes!");
},
"No": function() {
$( this ).dialog( "close" );
alert("You chose No!");
}
}
});
});
</script>
<div id="dialog-confirm" title="Are you sure you want to continue?">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
答案 5 :(得分:1)
我会用sweetalert https://sweetalert.js.org/guides/来实现这样的目标
swal("Are you sure you want to do this?", {
buttons: ["yes", "no"],
});
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
答案 6 :(得分:0)
使用对话框显示是或否
<div id="dialog_box" class="mnk-modal-bg" style="display:none">
<div id="dbg" class="mnk-modal-box">
<i class="uk-icon-exclamation-triangle" style="color:#757575; padding-right:5px;">
</i>Confirm?
<div class="uk-text-center" style="margin-top:10px;">
<button class="md-btn md-btn-small md-btn-primary" id="ok_btn">
<i class="uk-icon-save" style="padding-right:3px;"></i>OK
</button>
<button class="md-btn md-btn-small md-btn-danger" id="close_btn">
<i class="uk-icon-remove" style="padding-right:3px;"></i>Cancel
</button>
</div>
</div>
<script>
$("#ok_btn").click(function(){
alert("OK");
$("#dialog_box").hide();
});
$("#close_btn").click(function(){
alert("CANCEL");
$("#dialog_box").hide();
});
</script>