【问题标题】:How to show confirmation message in jQuery on button click event?如何在按钮单击事件中在 jQuery 中显示确认消息?
【发布时间】:2015-10-03 06:45:35
【问题描述】:

我正在 asp.net 中开发 Web 应用程序。我的要求是在每个按钮单击事件上显示确认消息,例如(插入、更新和删除按钮)。我在整个应用程序中使用 jQuery 消息框成功插入、更新和删除。

    function MessageBox(Title, InnerText) {
    try {
        var dialog = $('<p class="messagebox">' + InnerText + '</p>').dialog({
            title: Title,
            width: "240",
            modal: true,
            buttons: {
                "OK": function () {
                    dialog.dialog('close');
                }
            }
        });
    }
    catch (e) {
        MessageBox('Tracker Alert', e);
    }
}

调用按钮点击事件

Result = Save_UpdateData(2);
 if (Result > 0)
   {             
     ScriptManager.RegisterStartupScript(this, GetType(), "msg", "MessageBox('Tracker Alert', 'Record updated succesfully');", true);
     }

那么,如何使用与上述功能相同的jQuery消息框在按钮单击事件上显示确认消息?

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:
      <script type="text/javascript">
          $(window).on('mouseover', (function () {
              window.onbeforeunload = ConfirmLeave;
          }));
          $(window).on('mouseout', (function () {
              window.onbeforeunload = ConfirmLeave;
          }));
          function ConfirmLeave() {         
              return "";
          }
     var prevKey = "";
      $(document).keydown(function (e) {
          if (e.key == "F5") {
              window.onbeforeunload = ConfirmLeave;
          }
          else if (e.key.toUpperCase() == "W" && prevKey == "CONTROL") {
              window.onbeforeunload = ConfirmLeave;
          }
          else if (e.key.toUpperCase() == "R" && prevKey == "CONTROL") {
              window.onbeforeunload = ConfirmLeave;
          }
          else if (e.key.toUpperCase() == "F4" && (prevKey == "ALT" || prevKey == "CONTROL")) {
              window.onbeforeunload = ConfirmLeave;
          }
          prevKey = e.key.toUpperCase();
      });
    </script>
    

    【讨论】:

    • 我想要确认消息,例如(“您确定,您要更新此记录”)单击“确定”按钮然后调用“Save_UpdateData(2)”函数并单击“取消”然后关闭对话框。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    • 2020-10-03
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    相关资源
    最近更新 更多