【问题标题】:Attach jQuery dialog to Submit button in ASP.NET-MVC将 jQuery 对话框附加到 ASP.NET-MVC 中的提交按钮
【发布时间】:2010-04-30 18:09:30
【问题描述】:

我有一个提交按钮,它一直致力于在 ASP.NET-MVC 中提交我的表单。

我想在按钮单击时附加一个 jQuery 对话框。如果用户退出对话框,那么我也想退出提交。

我有与其他按钮挂钩的对话框,但没有提交。我该怎么做?

****已编辑****

这是我在另一个按钮上的对话框示例。

<button type="button" id="create-company" >Create Company</button>

<div id="popupCreateService_Line" title="Create a new service line"> 
<fieldset>
    <label for="service_line_name">Name:</label>
    <%= Html.TextBox("service_line_name") %>

    <label for="service_line_desc">Desc:</label>
    <%= Html.TextBox("service_line_desc") %>

</fieldset>
</div>

$("#create-service_line").click(function() {
                $('#popupCreateService_Line').dialog('open');
            });

【问题讨论】:

    标签: jquery asp.net-mvc dialog form-submit jquery-ui-dialog


    【解决方案1】:

    将此附加到您的表单加载事件..

      $(document).bind("keyup.EventPopupEvents", null, function(event)
    {
        if (event.keyCode == 27)
        {
            ShutdownEditEventForm();
        }
    });
    

    添加这两个函数:

     function ShutdownEditEventForm(){
    $(document).unbind(".EventPopupEvents");
    HidePopup($("#EventPopup"));}
    
    function HidePopup($popup){
    $("#PopupBackground").hide();
    $("#PopupBackground").remove();
    $popup.hide();}
    

    将此添加到您的表单加载以进行保存:

    $("#EditEventSaveButton").click(function() { SaveEvent(id, onSaveCallback); });
    

    第 :)

    【讨论】:

      【解决方案2】:

      通过对话框我不确定您是指一些自定义 css 对话框还是 javascript 中的确认对话框。对于后者,此代码应该可以正常工作。

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
              <title></title>
              <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
          </head>
          <body>
              <form method="get" action="focusout.htm">
                  <input type="submit" id="button" value="Submit" />
              </form>
              <script type="text/javascript">
      
                  $("#button").click(function () {
                      return confirm("are you sure you want to click?");
                  });
              </script>
          </body>
          </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-14
        • 1970-01-01
        • 1970-01-01
        • 2010-12-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多