我想在显示输出之前显示确认对话框

时间:2017-09-20 13:13:07

标签: javascript jquery html5 lift

我想显示一个确认对话框,如"你想继续吗?"如果"是",我想弹出显示表单输出的消息,如果"否"我想留在同一页上。

在下面显示的代码中,我导航到facto.html以显示输出,但我想显示一个带有内容的弹出窗口。我怎么能这样做?

我的index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Lift From Scratch</title>
      <script type="text/javascript">
         <!--
            function getConfirmation(){
               var retVal = confirm("Do you want to continue ?");
               if( retVal == true ){
                  <!--document.write("continue")-->
                  <!--window.location.href = '/facto.html';-->
                  return true;
               }
               else{
                  alert("Don't continue")
                  <!--window.location.href = 'index.html';-->
                  return false;
               }
            }
         //-->
      </script>
  </head>
  <body>
    <h1>Finding Factorial</h1>
    <div id="main" class="lift:surround?with=default&at=content">
        <form method="post">
          <table>
              <tr><td> Enter a Number:</td> <td><input name="num" type="number"></td></tr>
              <tr><td><input type="submit" value="Submit" onclick="getConfirmation();" formaction="facto"></td>
                  <td><input type="reset" value="Reset"></td>
              </tr>
          </table>
        </form>
      </div>
    </div>
  </body>
</html>

facto.html:
<div data-lift="factorial">
    <p>Factorial is: <span name="paramname"></span></p>
</div>

2 个答案:

答案 0 :(得分:0)

尝试这样的事情:

function validateMyForm()
{
  if( confirm('Are you sure?') )
  return true;   // will submit the form
  else
  return false;  // do not submit the form
}
<form name="myForm" onsubmit="return validateMyForm();"> 
  <input type="submit" value="Submit" />
</form>

答案 1 :(得分:0)

说实话,你可能想要回归这个问题。您可以使用Lift的SHtml.makeFormsAjax帮助程序将表单设为AJAX表单,然后使用SHtml.ajaxSubmit绑定提交按钮。您传递给ajaxSubmit的回调应返回JsCmdJsCmd可以触发弹出窗口的显示。您甚至可以使用SHtml.idMemoize来渲染弹出窗口的内容。

如果您在Lift group上更详细地描述这个问题,您可能会发现人们愿意帮助您解决一些更具体的问题。

相关问题