2017-09-20 35 views
1

我想显示一个确认对话框,如“您要继续吗?”如果“是”,我想弹出消息显示表单输出,如果“否”,我想留在同一页面上。我想在显示输出之前显示确认对话框

在下面显示的代码中,我导航到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> 

回答

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>

0

你会可能要回落到JavaScript的这一个,是诚实。您可以使用Lift的SHtml.makeFormsAjax助手将表单设置为AJAX表单,然后您可以使用SHtml.ajaxSubmit绑定您的提交按钮。您传递给ajaxSubmit的回拨应返回JsCmdJsCmd可以触发弹出窗口的显示。您甚至可以使用SHtml.idMemoize来呈现弹出窗口的内容。

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