嗨,下面我有一个提交按钮和一个在单击提交按钮时执行的 jquery 函数:
<p><input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" onClick="return myClickHandler();" /></p>
<script type="text/javascript">
function myClickHandler()
{
if (validation())
{
showConfirm();
return true;
}
return false;
}
</script>
现在您可以看到是否满足 validation() 函数,然后它将执行 showConfirm() 函数,该函数将执行下面的确认框:
function showConfirm()
{
var confirmMsg=confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Assessment." + "\n" + "\n" + "Are you sure you want to Proceed?" + "\n" );
if (confirmMsg == true)
{
submitform();
return true;
}
else
{
return false;
}
}
function submitform()
{
var fieldvalue = $("#QandA").val();
$.post("insertQuestion.php", $("#QandA").serialize(), function(data)
{
var QandAO = document.getElementById("QandA");
QandAO.submit();
});
alert("Your Details for this Assessment has been submitted");
}
我的问题是这个。如果用户在确认框中单击“确定”,则它会提交该页面,这很好。但是如果用户点击取消,那么它不应该提交页面。问题是即使单击了“取消”按钮,它仍在提交页面。为什么是这样?
更新:
我在下面尝试了这段代码,但仍然没有运气:
function myClickHandler()
{
if(validation())
{
return showConfirm();
}
return false;
}