Cha*_*iff 1 javascript php forms alert submit
我现在有这个.
//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
Run Code Online (Sandbox Code Playgroud)
我想改变它,以便当您按下:
a)"兑换"提交按钮时,它会提醒您说:"您确定要兑换吗?"
b)"Un-Redeem"SUBMIT按钮,它会提醒您:"您确定要取消兑换吗?"
我已经尝试了其中一些,包括提交上的ONCLICK,但没有一个工作..我相信这是因为我在ECHO中有它,我不得不删除阻止该功能发生的(")引号.
有人知道我能做到的另一种方式吗?
您可以使用Javascript确认功能.
if(confirm("Are you sure you want to Redeem?")) {
// do something
} else {
// do something
}
Run Code Online (Sandbox Code Playgroud)
您也可以通过在表单中添加以下代码在表单提交上执行此操作:
onsubmit="return confirm('Are you sure you want to Redeem?');"
Run Code Online (Sandbox Code Playgroud)
只有在用户点击"确定"时,表单才会提交.
这是解决方案:
//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
Run Code Online (Sandbox Code Playgroud)
编辑: 在这里添加转义字符:
//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
Run Code Online (Sandbox Code Playgroud)