jQuery对话框:确认单击提交按钮 [英] jquery dialog: confirm the click on a submit button
本文介绍了jQuery对话框:确认单击提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用jquery进行确认对话框,但是表单根本没有提交,这就是我得到的:
I'm trying to do a confirm dialog using jquery, but the form doesn't get submitted at all, this is what I got:
<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>
,如下所示:
You need to have your dialog button submit the <form>
, like this:
'Delete all items': function() {
$(this).dialog('close');
$("#myForm").submit();
}
您其余的代码是正确的,但是当前它只是关闭对话框并返回,您需要实际提交表单.另外,最好将其用作点击处理程序,而不是像这样的onclick
(已更新注释):
The rest of your code is correct, but it's currently just closing the dialog and returning, you need to actually submit the form. Also, it's better to do this as a click handler, instead of onclick
, like this (updated for comments):
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
类,如下所示:
Then just give your <input>
an class of delete
, like this:
<input class="delete" type="submit" value="delete" />
这篇关于jQuery对话框:确认单击提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文