我现在有这一点。
//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
我想,这样当你按下改变它:
一)“兑现”提交按钮它就会提醒你说:“你确定要兑换?”
二)“取消兑换”提交按钮它就会提醒你说:“你确定要取消兑换?”
我已经尝试了几个人,包括ONCLICK上提交,但没有工作..我相信这是因为我有它在ECHO,我不得不删除从发生停止功能(“)引号。
任何人都知道另一种方式我能做到吗?
这里是解决方案:
//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
您可以使用JavaScript的confirm功能。
if(confirm("Are you sure you want to Redeem?")) {
// do something
} else {
// do something
}
你也可以做到这一点的形式,通过添加以下代码到您的表单提交:
onsubmit="return confirm('Are you sure you want to Redeem?');"
如果用户点击“OK”的形式将只能提交。
使用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()"