我的HTML表单中有一个javascript,当用户单击Submit按钮时运行。它显示用户订单的总价格,并有"ok“和"cancel”按钮。我希望当用户单击"ok“时提交表单,但如果用户单击"cancel”则不提交。当前,当按下任一按钮时,它都会提交表单。如果单击“取消”,如何防止它提交表单?
这是我的简短剧本:
<script type="text/javascript">
function calculate()
{
var gPrice
var aPrice
var sPrice
var total
gPrice = document.getElementById("grapeorderquantity").value * 4.0;
aPrice = document.getElementById("appleorderquantity").value * 3.0;
sPrice = document.getElementById("strbryorderquantity").value * 3.5;
total = (gPrice + aPrice + sPrice) * 1.08;
confirm("This is your total: " + total);
}
</script>这是“我的提交”按钮的HTML:
<input type="submit" value="Submit" onClick="return calculate()" />发布于 2014-03-10 16:00:02
把这个放在你的职能上:
if(confirm("This is your total: " + total)) { // confirm returns true = OK clicked
return true;
}
else { // confirm returns false = Cancel clicked
return false;
}https://stackoverflow.com/questions/22305070
复制相似问题