在这里,我不想从提交按钮传递参数。谁能帮我相应地提示确认消息
return confirm("Are you sure to Approve/Reject/Delete ?");
我的html代码
<form name="pendingrequest" id="pendingrequest" action="formhandler.php" method="POST" onsubmit="return confirmation(this);">
<table >
<tr>
<td><input type="submit" name="action" value="Approve"></td>
<td><input type="submit" name="action" value="Reject"></td>
<td><input type="submit" name="action" value="Delete"></td>
</tr>
</table>
</form>
例如,如果有人点击“批准”,我想要这个:
return confirm("Are you sure to Approve?");
最佳答案
如果使用onsubmit
,则没有跨浏览器解决方案
执行此操作的唯一方法是将事件绑定(bind)到按钮而不是提交表单:
<!DOCTYPE html>
<html>
<head>
<script>
function init()
{
document.getElementById("pendingrequest").onsubmit = function(e)
{
console.log(e.target.value);
console.info(e.srcElement);
return false;
}
var submits = document.getElementsByClassName("submit-test");
for(var i=0;i<submits.length;i++)
{
submits[i].onclick = function(e){
var value = this.value;
return confirm("Are you sure to "+value+" ?");
}
}
}
</script>
</head>
<body onload="init()">
<form name="pendingrequest" id="pendingrequest" action="" method="POST" >
<table >
<tr>
<td><input class="submit-test" type="submit" name="action" value="Reject"></td>
<td><input class="submit-test" type="submit" name="action" value="Approve"></td>
<td><input class="submit-test" type="submit" name="action" value="Delete"></td>
</tr>
</table>
</form>
</body>
</html>
关于javascript - 三个提交按钮的确认,其值作为确认消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19724852/