Select2在引导模态中不起作用 [英] Select2 not working inside bootstrap modal

查看:72
本文介绍了Select2在引导模态中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在引导程序模式内使用select2,但是它无法自动获取焦点,并且向下箭头和向上箭头不适用于填充列表.

I am trying to use select2 inside bootstrap modal but it is not getting the focus automatically as well as down and up arrows are not working for the populated list.

当我将其置入模式弹出窗口之外时,同一个select2也可以工作.

The same select2 works when I put it outside the modal popup.

搜索时,我发现很多人都面临着同样的问题,并找到了这篇文章

When I searched, I found many are facing this same problem and found this post

Select2嵌入引导程序模式时不起作用

我从中实施了这两种解决方案

I implemented both the solutions from it

  1. 从模式弹出窗口中删除了tabindex.
  2. modal.js文件中enforceFocus函数的注释代码.
  1. Removed tabindex from modal popup.
  2. Commented code of enforceFocus function in modal.js file.

但是它仍然无法正常工作!知道我还可能缺少什么吗?

But it is still not working! Any idea what I could still be missing?

编辑1

当从模态div中删除tabindex时,它在firefox上有效,但对于IE9

It works on firefox when tabindex is removed from the modal div but not with IE9

Edit2

我发现删除tabindex实际上未被IE9识别,因为我仍然可以通过IE中的转义键隐藏弹出窗口,而不能在Firefox中隐藏

I found that removing tabindex is actually not getting recognized by IE9 because I can still hide the popup by escape key in IE but not in Firefox.

推荐答案

发现了问题!

实际上,我是使用html属性(通过按钮等)打开模式的

Actually I was opening modal using html attributes on by button like

 data-target="#modalAttachment"

而我应该使用JavaScript代码打开模式,以使enforceFocus更改生效 当我开始使用它打开模态时,enforceFocus函数更改为有效

while I should use javascript code to open the modal to make enforceFocus change takes affect when I started using this to open the modal, enforceFocus function changed worked

$('#modalAttachment').modal('show');

谢谢!

这篇关于Select2在引导模态中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆