Bootbox - 确认模态对话框需要回调函数......但我有一个

Bootbox - Confirm Modal DIalog Box requires Callback function ... but I have one

为什么下面的代码return会出错:

<script type="text/javascript">
    $(document).ready(function () {
        $("#chkIssueCredit").change(function () {
            if (!$(this).prop('checked')) {
                bootbox.confirm("Are you sure you do not want to issue a credit? Please confirm."), function (result) {
                    if (result) {
                        $(this).prop('checked', true);
                    }
                }
                return false;

                //if (!confirm("Are you sure you do not want to issue a credit? Please confirm.")) {
                //    $(this).prop('checked', true);
                //};
            };
        });
    });
</script>

您将在第一个参数(消息)之后立即关闭确认方法。在这里试试这个:

<script type="text/javascript">
    $(document).ready(function () {
        $("#chkIssueCredit").change(function () {
            if (!$(this).prop('checked')) {
                bootbox.confirm("Are you sure you do not want to issue a credit? Please confirm.", function (result) {
                    if (result) {
                        $(this).prop('checked', true);
                    }
                });
                return false;

                //if (!confirm("Are you sure you do not want to issue a credit? Please confirm.")) {
                //    $(this).prop('checked', true);
                //};
            };
        });
    });
</script>

你能看出区别吗?