简体   繁体   English

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

[英]I want to display a confirmation dialog before displaying output

I want to display a confirmation dialog box like "Do you want to continue?" 我想显示一个确认对话框,例如“您要继续吗?”。 If "yes", I want to popup a message displaying form output, if "No" I want to stay on the same page. 如果为“是”,我想弹出一条消息,显示表单输出,如果为“否”,我想保留在同一页面上。

In the code shown below I am navigating to facto.html for displying the output, but I want to show a popup with its contents instead. 在下面显示的代码中,我导航至facto.html以显示输出,但我想显示一个包含其内容的弹出窗口。 How can I do that? 我怎样才能做到这一点?

My index.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>

Try something like this: 尝试这样的事情:

 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> 

You're going to probably want to fall back to JavaScript for this one, to be honest. 老实说,您可能会希望使用JavaScript。 You can make the form an AJAX form using Lift's SHtml.makeFormsAjax helper, then you can bind your submit button using SHtml.ajaxSubmit . 您可以使用Lift的SHtml.makeFormsAjax帮助器将表单制作为AJAX表单,然后可以使用SHtml.ajaxSubmit绑定提交按钮。 The callback you pass to ajaxSubmit should return a JsCmd . 传递给ajaxSubmit的回调应返回JsCmd That JsCmd can trigger the display of the popup. JsCmd可以触发弹出窗口的显示。 You can even render the popup's contents by using SHtml.idMemoize . 您甚至可以使用SHtml.idMemoize呈现弹出窗口的内容。

If you describe this question in a little more detail on the Lift group , you will probably find folks willing to help you with some of the more specific aspects of it. 如果您在“ 提升”小组中更详细地描述此问题,则可能会发现有人愿意为您提供一些更具体的方面的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM