使用保存和放弃按钮进行确认

问题描述

| 我们如何在JavaScript中创建带有保存和丢弃按钮的确认警报? 如果我们使用代码
confirm(\'Do you want to save it?\');
我们将收到一个确定取消的警报框。 我们怎样才能使OK按钮的文本保存为文件,将其他按钮丢弃?     

解决方法

        您无法修改默认的javascript方法\“确认\”。但是,您可以使用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\"); 
        } 
    }
  });
}
    ,        这是不可能的 更多答案     ,         连接一些吨JS框架。例如jQuery + UI 覆盖window.confirm方法,方法是将其包装为您喜欢的JS UI框架。 利润!!!