如何使对话框的确认按钮适应表单的按钮

时间:2017-08-25 00:42:49

标签: jquery performance jquery-ui jquery-plugins

我会在表单中使用一个对话框。我可以在表单中显示对话框。我希望当我单击对话框中的“是”按钮时,我可以与表单上的“后退”按钮具有相同的行为。你是怎样做的?谢谢您的帮助。在我开发的代码下面:

 <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link href="jquery-ui-1.10.4/css/custom-theme/jquery-ui-1.10.4.custom.css" rel="stylesheet">
    <script src="jquery-ui-1.10.4/js/jquery-1.10.2.js"></script>
    <script src="jquery-ui-1.10.4/js/jquery-ui-1.10.4.js"></script>

            <title>Test</title>
    <script>
    let validation = function(form) {

      $("#dialog").dialog({
        modal: true,
        buttons: {
          Yes: function() {
            $(this).dialog("close");
            document.getElementById("myForm-previous").submit();
          },
          No: function() {
            $(this).dialog("close");
          }
        }
      });

      return false;

    }
    </script>
        </head>

        <body>


        <div id="dialog" title="Confirmation">
    <p>Warning!!!
    You will lose your data!
    Do you want to continue ?</p>
        </div>
    <form id="myForm" name="myFrom"/>
            <input type="file"/><br/>
            <input type="file"/><br/>
            <input id="myForm-previous" value="BackWard" type="submit" onclick="return validation()"/><br/>
            <input id="myForm-next" value="Forward" type="submit"/>

    </form>
    </body> 
    </html>

1 个答案:

答案 0 :(得分:0)

你在这里有错误:

   document.getElementById("myForm-previous").submit();

如果您想提交表格,请使用FORM identifyicator,而不是BUTTON:

   document.getElementById("myForm").submit();