[英]jquery modal dialog before form submit
I have a form on a page, and I am trapping the click action on two submit buttons. 我在页面上有一个表单,并且将点击动作限制在两个提交按钮上。 There is another submit button that is not trapped (ie I dont need to show a modal for this button).
还有一个不会被困的提交按钮(即,我不需要为此按钮显示模式)。
So, my obvious problem is that I need to block the submit action when the modal first opens, and I then need to force the submit when the user actually clicks the OK button in the modal. 所以,我的明显问题是,当模式第一次打开时,我需要阻止提交操作,然后当用户实际单击模式中的“确定”按钮时,我需要强制提交。 However, because each button has a specific name and value associated with it (which the back-end script needs to know), a $('#myform').submit() method will therefore not work.
但是,由于每个按钮都有一个与之关联的特定名称和值(后端脚本需要知道),因此$('#myform')。submit()方法将不起作用。
function something(msg) {
var $dialog = $('<div></div>').html(msg).dialog({
autoOpen: false,
title: 'Please confirm...',
modal: true,
buttons: {
"OK": function () {
$dialog.dialog('close');
//submit needs to happen here
},
Cancel: function () {
$(this).dialog("close");
}
}
});
$dialog.dialog('open');
event.preventDefault();
return false;
}
I would include a hidden field to take on the name and value of the submit button clicked: 我将包含一个隐藏字段,以接受所单击的提交按钮的名称和值:
<input type="hidden" name="subName" value="" />
$("#submit_button_one").function() {
$("input[name='subName']").attr("name", $(this).attr("name")).val(($(this).val());
something("message");
return false;
});
$("#submit_button_two").function() {
$("input[name='subName']").attr("name", $(this).attr("name")).val(($(this).val());
something("message");
return false;
});
function something(msg, act) {
// ...
//submit needs to happen here
$('#myform').submit()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.