使用保存和放弃按钮确认

发布于 2024-11-10 11:53:25 字数 169 浏览 8 评论 0原文

我们如何在 JavaScript 中创建一个带有保存和放弃按钮的确认警报? 如果我们使用该代码,

confirm('Do you want to save it?');

我们将收到一个带有“确定取消”的警告框。 如何让ok按钮的文字为保存,另一个为放弃?

How can we create a confirmation alert in javascript with a save and discard button in it?
If we use the code

confirm('Do you want to save it?');

We will get an alert box with ok cancel.
How can we make the text of ok button as save and the other as discard?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

国粹 2024-11-17 11:53:25

您无法修改默认的 javascript 方法“confirm”。但是,您可以覆盖它,例如使用 jQuery UI 对话框:

window.confirm = function (message) {
  var html = "<div style='margin:20px;'><img style='float:left;margin-right:20px;' src='/img/confirm.gif' alt='Confirm'/><div style='display:table;height:1%;'>" + message + "</div></div>";

  $(html).dialog({ closeOnEscape: false,
    open: function (event, ui) { $('.ui-dialog-titlebar-close').hide(); },
    modal: true,
    resizable: false,
    width: 400,
    title: "Confirmation",
    buttons: { 
        "Save": function () {
            //Do what you need
        },
        "Cancel": function () {
            $(this).dialog("close"); 
        } 
    }
  });
}

You cannot modify the default javascript method "confirm". But, you can override it, for example, with jQuery UI dialog:

window.confirm = function (message) {
  var html = "<div style='margin:20px;'><img style='float:left;margin-right:20px;' src='/img/confirm.gif' alt='Confirm'/><div style='display:table;height:1%;'>" + message + "</div></div>";

  $(html).dialog({ closeOnEscape: false,
    open: function (event, ui) { $('.ui-dialog-titlebar-close').hide(); },
    modal: true,
    resizable: false,
    width: 400,
    title: "Confirmation",
    buttons: { 
        "Save": function () {
            //Do what you need
        },
        "Cancel": function () {
            $(this).dialog("close"); 
        } 
    }
  });
}
瑶笙 2024-11-17 11:53:25

这是不可能的

更多答案

this is not possible

more answers

苏辞 2024-11-17 11:53:25
  1. 连接一些吨JS框架。例如 jQuery+UI
  2. 覆盖 window.confirm 方法,将其作为您最喜欢的 JS UI 框架的包装器。
  3. 利润!!!
  1. Connect some of the tons JS framework. For example jQuery+UI
  2. Overwrite window.confirm method, by makin it as wrapper to your favorite JS UI framework.
  3. PROFIT!!!
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文