引导箱-确认模态对话框需要回调功能...但是我有一个

时间:2019-02-18 15:01:38

标签: jquery bootstrap-4 bootbox

以下代码为什么返回错误:

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

1 个答案:

答案 0 :(得分:1)

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

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

您能看到区别吗?