我有一个对话框需要在用户点击提交时显示。然后,用户必须接受我们资源的使用条款。
<script>
$(document).ready(function() {
$(function() {
var Form;
$("#confirm").dialog({
height: 200,
width: 200,
modal: true,
buttons: {
'No': function() { // No works (since I only need to close the box)
$(this).dialog("close");
},
'Yes': function() { // This is not working. The button just keeps me on the same page with no submission
Form.submit();
}
}
});
});
$("#acceptform").submit(function() { // This is the form that a user has to submit before the dialog box appears
Form = this;
$('#confirm').dialog('open');
return false;
});
});
</script>
如果还有其他事情需要更好地提出这个问题,请告诉我。
答案 0 :(得分:1)
解决方案的关键是确定“确认”框是否已经打开...如果已经打开,则提交表单,然后表单需要继续...
在你执行form.submit的情况下,代码agaiin将提交处理程序并返回false ...因此表单submition失败。 的 DEMO 强>
$(document).ready(function() {
var FORM=$("#acceptform");
$(function() {
$("#confirm").dialog({
height: 200,
width: 200,
modal: true,
buttons: {
'No': function() { // No works (since I only need to close the box)
$(this).dialog("close");
FORM.data("confirmProgress",false);
},
'Yes': function() { // This is not working. The button just keeps me on the same page with no submission
FORM.submit();
FORM.data("confirmProgress",false);
}
}
});
});
FORM.submit(function() { // This is the form that a user has to submit before the dialog box appears
if(!$(this).data("confirmProgress")){
$(this).data("confirmProgress",true);
$('#confirm').dialog('open');
return false;
}else{
return true;
}
});
});
</script>