gpt4 book ai didi

jquery 对话框 : confirm the click on a submit button

转载 作者:行者123 更新时间:2023-12-03 22:29:23 26 4
gpt4 key购买 nike

我正在尝试使用 jquery 进行确认对话框,但表单根本没有提交,这就是我得到的:

    <script type="text/javascript">
var currentForm;
$(function() {
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
'Delete all items': function() {
currentForm.submit();
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
}
});
});

function ask() {
currentForm = $(this).closest('form');
$("#dialog-confirm").dialog('open');
}
</script>
<form ... >
<input type="submit" value="delete" onclick="ask();return false;" />
</form>

最佳答案

您需要让对话框按钮提交 <form> ,像这样:

               'Delete all items': function() {
$(this).dialog('close');
$("#myForm").submit();
}

您的其余代码是正确的,但目前只是关闭对话框并返回,您需要实际提交表单。另外,最好将其作为点击处理程序来执行,而不是 onclick ,像这样(更新评论):

    var currentForm;
$(function() {
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
'Delete all items': function() {
$(this).dialog('close');
currentForm.submit();
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
$(".delete").click(function() {
currentForm = $(this).closest('form');
$("#dialog-confirm").dialog('open');
return false;
});
});

然后只需提供您的 <input>一类 delete ,像这样:

<input class="delete" type="submit" value="delete" />

关于jquery 对话框 : confirm the click on a submit button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2881706/

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