gpt4 book ai didi

javascript - 使用 jquery 手动提交带有特定提交的表单

转载 作者:行者123 更新时间:2023-11-28 00:13:33 25 4
gpt4 key购买 nike

我有一个带有两个提交按钮的表单。

我希望用户在删除之前看到一个确认窗口,如果同意,则提交删除表单

<script>
$(document).ready(function(){
$("#delete").on('click', function (event){
var form = $('form');
event.preventDefault();
if(confirm("You cannot revert this action. Item will be deleted pemanently. Delete anyway?")){
form.submit() //which button will it assume it was used?

}
});

});
</script>

最佳答案

您可以仅在确认警报后阻止表单,而不是始终阻止表单提交。

<script>
$(document).ready(function(){
$("#delete").on('click', function (event){
var form = $('form');
if(!confirm("You cannot revert this action. Item will be deleted pemanently. Delete anyway?")){
event.preventDefault();

}
});

});
</script>

关于javascript - 使用 jquery 手动提交带有特定提交的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30664230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com