<form onsubmit="return confirm('Are you sure you want to rollback deletion of candidate table?')">
<input type='submit' name='delete' value='Undo' />
<input type='submit' name='no' value='No' />
当用户单击第二个提交按钮时,即No
我想将确认对话框显示为“您确定要提交交易”。
<form method='post'>
<input type='submit' name='undo' value='Undo' onclick="return confirm('Are you sure you want to rollback deletion of candidate table?')"/>
<input type='submit' name='no' value='No' onclick="return confirm('Are you sure you want to commit delete and go back?')"/>
</form>
工作得很好。刚刚更改onsubmit()
为onclick()
. 因为在这种情况下两者的功能是相同的。
您可以绑定到 onclick 而不是 onsubmit - 见下文。
<script>
function submitForm() {
return confirm('Rollback deletion of candidate table?');
}
<script>
<form>
<input type='submit' onclick='submitForm()' name='delete' value='Undo' />
<input type='submit' onclick='submitForm()' name='no' value='No' />
</form>
或者,使用 jQuery:
<script>
$(document).ready(function() {
$('form input[type=submit]').click(function() {
return confirm('Rollback deletion of candidate table?');
});
});
<script>
<form onsubmit="submitFunction();">
<input type='submit' name='delete' value='Undo' />
<input type='button' onclick="declineFunction()" name='no' value='No' />
</form>
我不会尝试创建提交,而只是创建一个具有 onclick="function()" 的按钮,然后使用 javascript 设置一个变量以查看他们单击它的次数和 alert();
希望这会有所帮助:D
这是一个基于事件侦听器的解决方案,它避免了内联事件处理程序(如果您的站点具有禁止内联 JavaScript 的内容安全策略,则很有用):
HTML:
<form method="post">
<input type="submit" id="deleteButton" name="delete" value="Undo" />
<input type="submit" id="noButton" name="no" value="No" />
</form>
JS:
document.getElementById("deleteButton").addEventListener("click", function(evt) {
if (!confirm("Are you sure you want to rollback deletion of candidate table?")) {
evt.preventDefault();
}
});
document.getElementById("noButton").addEventListener("click", function(evt) {
if (!confirm("Are you sure you want to commit the transaction?")) {
evt.preventDefault();
}
});
只需使用两个相同的形式。每个按钮一个:
<form onsubmit="return confirm('Are you sure you want to rollback deletion of candidate table?')">
<input type='submit' name='delete' value='Undo' />
</from>
<form onsubmit="return confirm('Are you sure you want to rollback deletion of candidate table?')">
<input type='submit' name='no' value='No' />
</from>
此外,如果您进行研究,您会发现这些: