2

我有一个对话框需要在用户单击提交时显示。然后,用户必须要么接受我们资源的使用条款。

<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>

如果有任何其他事情需要更好地问这个问题,请告诉我。

4

1 回答 1

1

解决方案的关键是确定确认框是否已经打开......如果它已经打开,那么表单正在提交,那么表单需要继续......

在你的情况下,当你做 form.submit .. 代码再次进入提交处理程序并返回 false ......所以表单提交失败。 演示

$(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>
于 2013-05-13T15:49:11.510 回答