gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 04:10:28 25 4
gpt4 key购买 nike

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

在下面显示的代码中,我导航到 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 - 我想在显示输出之前显示确认对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46323045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com