【问题标题】:Bootbox - Confirm Modal DIalog Box requires Callback function ... but I have oneBootbox - Confirm Modal Dialog Box 需要回调函数……但我有一个
【发布时间】:2019-02-18 15:01:38
【问题描述】:

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

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

【问题讨论】:

  • 代码会为您产生什么错误?请edit问题删除重复,并添加错误消息。如果可能,通过添加适当的 html 并将其转换为可执行的 sn-p 将问题转换为 minimal reproducible example

标签: jquery bootstrap-4 bootbox


【解决方案1】:

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

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

你能看出区别吗?

【讨论】:

    猜你喜欢
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 2021-03-31
    • 2018-06-11
    • 2020-09-25
    • 1970-01-01
    • 2013-09-08
    相关资源
    最近更新 更多