[英]I want to display a confirmation dialog before displaying output
我想顯示一個確認對話框,例如“您要繼續嗎?”。 如果為“是”,我想彈出一條消息,顯示表單輸出,如果為“否”,我想保留在同一頁面上。
在下面顯示的代碼中,我導航至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>
嘗試這樣的事情:
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>
老實說,您可能會希望使用JavaScript。 您可以使用Lift的SHtml.makeFormsAjax
幫助器將表單制作為AJAX表單,然后可以使用SHtml.ajaxSubmit
綁定提交按鈕。 傳遞給ajaxSubmit
的回調應返回JsCmd
。 JsCmd
可以觸發彈出窗口的顯示。 您甚至可以使用SHtml.idMemoize
呈現彈出窗口的內容。
如果您在“ 提升”小組中更詳細地描述此問題,則可能會發現有人願意為您提供一些更具體的方面的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.