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



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

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

您可以看到差异吗?

最新更新