我有一个包含文本框的sweetalert盒子。 sweetalert在自举模式盒子上打开。在Firefox中,我试图在文本框中单击,但它没有获得焦点。
这是我的Sweet Alert代码:
swal(
{
title: "Create New Design",
input: "text",
showCancelButton: true,
inputPlaceholder: "Title",
preConfirm: function(input)
{
// code to validate the input
}
});
这是截图:
根据@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 () { };