我试图弄清楚当有人单击链接时如何弹出确认/拒绝框。当他们单击“确定”时,会将他们带到一个地方,当他们单击“取消”时,会将他们带到另一个地方。我的大部分经验是使用 PHP,但通常我可以采用其他 JavaScript 函数并使它们工作......不过似乎无法弄清楚这一点。
这是我的脚本:
function confirmChoice(name, newid){
answer = confirm("Transfer Ownership of this task to " + name +
"? Press Cancel to decline.")
if (answer == 1) {
location = "transfer.php?task=<? echo $taskid; ?>&from=<? echo ownerid; ?>&to=" + newid;
} elseif (answer==0) {
location = "decline.php?task=<? echo $taskid; ?>";
}
}
任何帮助将不胜感激!
编辑:好的,按照建议更改了代码。现在它是:
function confirmChoice(name, newid){
var answer = confirm("Transfer Ownership of this task to " + name + "? Press Cancel to decline.")
if (answer){
location = "transfer.php?task=<? echo $thistaskid; ?>&from=<? echo $ownerid; ?>&to=" + newid;
}else{
location="decline.php?task=<? echo $thistaskid; ?>";
}
}
使用的链接是:
<a href="#" onclick="confirmChoice(<? echo $requestorname; ?>, <? echo $newid; ?>); return false;"><? echo $requestorname; ?> Requested Ownership</a>
我还是没有收到确认框...