21

我只能找到confirm()提供确定/取消按钮的功能。有没有办法给出是/否按钮?

4

7 回答 7

8

Javascript 提供了 3 个模态框。 prompt,confirmalert. 这些都不满足您的要求。

有大量的 js 模态弹出解决方案。这是一个例子。

于 2008-08-21T03:31:16.097 回答
2

不。

相反,您可以使用浏览器模式弹出窗口。

于 2008-08-21T03:25:45.470 回答
2

就像上面其他人所说的那样,您使用 OK/Cancel 卡住了confirm()

不过,我想推荐这个jQuery插件:jqModal。我在最近的 3 个项目中使用了它,并且对每个项目都非常有效。具体看看这个例子:

6)。乐趣!覆盖——a。查看(警报),b。查看(确认) 现在是时候展示 jqModal 的实际用途了——覆盖标准的 alert() 并确认对话框!笔记; 由于 javascript 的单线程特性,confirm() 函数必须传递一个回调——它不返回真/假。

于 2008-08-21T03:48:47.113 回答
1

不,但是有 JavaScript 库可以为您完成此任务。举个例子,Ext JS可以用来创建一个消息框对话框

于 2008-08-21T03:32:42.487 回答
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>
于 2014-04-07T14:13:10.417 回答
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>

于 2018-01-07T21:07:49.507 回答
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>
于 2016-07-04T12:16:11.667 回答