【问题标题】:swal().then(function ()) not firing in Internet Explorer 11swal().then(function ()) 在 Internet Explorer 11 中未触发
【发布时间】:2018-01-19 11:22:24
【问题描述】:

希望你能帮我解决这个问题,我想我缺少一件小事。

我的_layout.cshtml 包含所有相关脚本,让甜心在 IE 上工作:

(这在以前的版本中可以工作,虽然我们已经有一段时间不需要支持 IE)

@if (Request.Browser.Browser == "IE" || Request.Browser.Browser == "InternetExplorer")
{
    <script src="https://npmcdn.com/es6-promise@3.2.1"></script>
}
<script type="text/javascript" src="~/bower_components/sweetalert2/dist/sweetalert2.min.js"></script>

<!--[if IE 9]>
    <script src="~/bower_components/sweetalert2-ie9/dist/sweetalert2.min.js"></script>
<![endif]-->

如您所见,promise 包含在 sweetalert2 之前,我知道这很好,因为我的表单提交上的 sweetalert 功能。

问题是当我单击“是”时,.then() 函数没有被命中,在调试器中它被忽略并直接跳过。这仅与 IE 有关,目前仅在 11 中测试过,我现在只是要检查其他版本。我无法弄清楚为什么会这样,有什么想法吗?

相关的.js:

vm.PostCommentData = function (postData, event) {
    var $commentTextBoxId = '#' + vm.createRemedyCommentId;

    if ($($commentTextBoxId).length) {
        var globalTranslations = globalDashboard.GetTranslations();

        swal({
            title: translations.AreYouSureYouWantToSubmit,
            text: '',
            type: 'warning',
            showCancelButton: true,
            confirmButtonText: '<i class="fas fa-thumbs-up"></i> ' + globalTranslations.Yes,
            cancelButtonText: '<i class="fas fa-thumbs-down"></i> ' + globalTranslations.No,
            confirmButtonClass: 'btn btn-success',
            cancelButtonClass: 'btn btn-danger',
            buttonsStyling: false
        }).then(function () {
            vm.state($(event.currentTarget).data('state'));
            var newComment = $($commentTextBoxId).val();
            var errorMessage = $("<ul class='list-unstyled' />");
            var hasErrored = false;

            if (vm.selectedQuestions().length == 0) {
                errorMessage.append("<li>" + translations.AtLeastAQuestionIsRequiredToBeSelected + "</li>");
                hasErrored = true;
            }

            if (vm.selectedDealershipId() == undefined) {
                errorMessage.append("<li>" + translations.PleaseSelectADealership + "</li>");
                hasErrored = true;
            }

            if (newComment === '') {
                errorMessage.append("<li>" + translations.CommentTextIsRequired + "</li>");
                hasErrored = true;
            }

            if (hasErrored) {
                swal({
                    title: translations.Warning,
                    html: errorMessage,
                    type: 'error',
                    buttonsStyling: false,
                    confirmButtonText: '<i class="fas fa-check"></i> ' + globalTranslations.OK,
                    confirmButtonClass: 'btn btn-success'
                });
            }
            else {

                var successMessage = translations.YourRemedyHasBeenSubmitted;
                if (vm.selectedQuestions().length > 1)
                    successMessage = translations.YourRemediesHaveBeenSubmitted;

                swal({
                    title: translations.Completed,
                    text: vm.globalViewModel().decodeEntities(successMessage),
                    type: 'success',
                    buttonsStyling: false,
                    confirmButtonText: '<i class="fas fa-check"></i> ' + globalTranslations.OK,
                    confirmButtonClass: 'btn btn-success'
                }).then(function () {
                    $(remedyBoxId + " .overlay").show();
                    $('#create-remedy-commentFormId').submit();
                });
            }
        });
    }
}

vm.knockout.js 绑定的,但我几乎完全可以肯定淘汰赛在这方面没有任何作用。

【问题讨论】:

    标签: javascript internet-explorer sweetalert2


    【解决方案1】:

    经过一番摸索,我意识到这需要一个 polyfill 服务。

    我的 IE 标签已更新为:

    @if (Request.Browser.Browser == "IE" || Request.Browser.Browser == "InternetExplorer")
        {
            <script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
            <script src="https://npmcdn.com/es6-promise@3.2.1"></script>
        }
    

    一定要喜欢 1 行修复!

    【讨论】:

    猜你喜欢
    • 2018-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多