php动作代码与javascript confirmAction()不工作



我有一个php文件假设有一个按钮通过调用JavaScript内置函数来执行一些checkout功能操作

<a href="index.php" class="btn btn-danger btn-xs" > onclick="confirmAction()" <i class="icon-edit">Check out</a>

我使用confirmAction()这样的

<script>
// The function below will start the confirmation dialog
function confirmAction() {
let confirmAction = confirm("Dose the maintenance finished yet?");

if (confirmAction) {

alert("Action Done")

} 
else {
alert("Action canceled");
}
}
</script>

如果用户按下ok,我想做php代码它应该做post action

controller.php?action=checkout&code=<?php echo $result->CONFIRMATIONCODE; ?>

,但我没有成功地使它在内工作TRUEjavascript函数

中的大小写基本上我试着在没有的情况下运行php代码标签但是我失败了

有什么建议吗?由于

使用如下代码,如果你想在取消事件中重定向,然后添加如下代码:window.location.href = 'http://www.google.com';

形式:

<form method="POST" action="controller.php" id="myForm">
<input type="hidden" name="action" value="checkout"> 
<input type="hidden" name="code" value="put code here"> 
<a href="javascript:void(0)" class="btn btn-danger btn-xs" onclick="return confirmAction()" ><i class="icon-edit">Check out</i></a>
</form>

脚本:

function confirmAction() {
let confirmAction = confirm("Dose the maintenance finished yet?");

if (confirmAction) {

alert("Action Done");
document.getElementById("myForm").submit();
} 
else {
alert("Action canceled");
return false;
}
} 

最新更新