16
<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我想将确认对话框显示为“您确定要提交交易”。

4

5 回答 5

29
<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(). 因为在这种情况下两者的功能是相同的。

于 2013-08-03T23:10:44.180 回答
2

您可以绑定到 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>
于 2013-08-03T23:11:58.123 回答
0
<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

于 2013-08-03T23:28:29.207 回答
0

这是一个基于事件侦听器的解决方案,它避免了内联事件处理程序(如果您的站点具有禁止内联 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();
    }
});
于 2018-02-26T17:22:57.423 回答
-1

只需使用两个相同的形式。每个按钮一个:

<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>

此外,如果您进行研究,您会发现这些:

于 2013-08-03T22:55:30.050 回答