1

我目前有这个。

 //other stuff up here - not important
    echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='1' /><input type='hidden' name='id' value='" . $id . "' /><input type='submit' name='Redeem' value='Redeem'></form></td>";
    } else {
    echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='0' /><input type='hidden' name='id' value='" . $id . "' /><input type='submit' name='Un-Redeem' value='Un-Redeem'></form></td>";
//other stuff down here - not important

我想更改它,以便当您按下:
a)“兑换”提交按钮时,它会提醒您说:“您确定要兑换吗?”
b) 'Un-Redeem' 提交按钮,它会提醒您说:“您确定要取消赎回吗?”

我已经尝试了其中的一些,包括提交时的 ONCLICK,但没有一个起作用。我相信这是因为我在 ECHO 中有它,我不得不删除阻止该功能发生的 (") 引号。

有人知道我可以做到的另一种方式吗?

4

3 回答 3

6

您可以使用 Javascript 确认功能。

if(confirm("Are you sure you want to Redeem?")) {
    // do something
} else {
    // do something
}

您也可以通过将以下代码添加到表单中来在表单提交上执行此操作:

onsubmit="return confirm('Are you sure you want to Redeem?');"

只有当用户单击“确定”时,表单才会提交。

于 2013-01-29T20:48:42.593 回答
5

这是解决方案:

     //other stuff up here - not important
        echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='1' /><input type='hidden' name='id' value='" . $id . "' />
              <input type='submit' name='Redeem' value='Redeem' onclick="return confirm('Are you sure you want to Redeem?')"></form></td>";
        } else {
        echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='0' /><input type='hidden' name='id' value='" . $id . "' />
              <input type='submit' name='Un-Redeem' value='Un-Redeem' onclick="return confirm('Are you sure you want to Un-Redeem?')" ></form></td>";
    //other stuff down here - not important

编辑: 在这里添加了转义字符:

 //other stuff up here - not important
        echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='1' /><input type='hidden' name='id' value='" . $id . "' />
              <input type='submit' name='Redeem' value='Redeem' onclick=\"return confirm('Are you sure you want to Redeem?')\"></form></td>";
        } else {
        echo "<td><form action='redeem.php' method='post' id='form'><input type='hidden' name='redeem' value='0' /><input type='hidden' name='id' value='" . $id . "' />
              <input type='submit' name='Un-Redeem' value='Un-Redeem' onclick=\"return confirm('Are you sure you want to Un-Redeem?')\" ></form></td>";
    //other stuff down here - not important
于 2013-01-29T20:54:05.370 回答
0

使用 javascript 确认功能。如果确认返回 false,表单将不会提交。

<form action='redeem.php' method='post' id='form' onSubmit="return confirm('Are you sure you want to redeem')">

如果您想在用户单击取消时执行其他操作,那么您需要创建一个自定义函数:

function my_confirm() {
    if( confirm("Are you sure you want to redeem?") ) {
        return true;
    }
    else {
        // do something 
        return false;
    }
}

在表单标签上:

onSubmit="return my_confirm()"
于 2013-01-29T20:54:57.230 回答