0

我有一个包含文本框的sweetalert 框。sweetalert 在引导模式框上打开。在 Firefox 中,我试图单击文本框,但没有获得焦点。

这是我的甜蜜警报代码:

swal(
        {
            title:              "Create New Design",
            input:              "text",
            showCancelButton:   true,
            inputPlaceholder:   "Title",
            preConfirm: function(input)
            {
                // code to validate the input
            }
        });

这是屏幕截图:

在此处输入图像描述

4

1 回答 1

3

根据@limonte在评论中给出的已知问题,Boostrap 模态框有一个名为 enforceFocus 的函数,只要我们尝试将焦点放在未包含在 BS 模态框内的元素上,它就会立即将焦点放在模态本身上。

所以现在我所做的是从下面的文档中取消绑定focusin.bs.modal事件。它工作正常。

jQuery('#myModal').on('shown.bs.modal', function() {
    jQuery(document).off('focusin.modal');
});

除了彼此之外,我们没有任何其他解决方案可以做到这一点。

我们可以使用以下行覆盖该特定方法:

jQuery.fn.modal.Constructor.prototype.enforceFocus = function () { };
于 2017-05-15T12:31:54.407 回答