【问题标题】:Textbox in Sweet Alert not focus-able while on bootstrap modal in FirefoxSweet Alert 中的文本框在 Firefox 的引导模式下无法聚焦
【发布时间】:2017-05-15 11:03:42
【问题描述】:

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

这是我的甜蜜警报代码:

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

这是截图:

【问题讨论】:

标签: javascript firefox bootstrap-modal sweetalert sweetalert2


【解决方案1】:

根据 @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 () { };

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多