BootStrap模态框和select2合用时input无法获取焦点的解决方法
2017-09-01 14:00
926 查看
在bootstrap的模态框里使用select2插件,会导致select2里的input输入框没有办法获得焦点,没有办法输入.
解决方法:
1.
把页面中的
tabindex="-1"删掉(测试成功):
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="myModalLabel">Panel</h3> </div> <div class="modal-body" style="max-height: 800px"> <div id="myModal" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="myModalLabel">Panel</h3> </div> <div class="modal-body" style="max-height: 800px">
可以在onshown方法里面做处理,主要原理就是因为bootstrap的
tabindex='-1',占用了select2的
tabindex='0',脚本做处理 模态框显示出来后,将模态框的tabindex属性删掉
BootstrapDialog.show({ onshown: function (dialogRef) { $("#"+dialogRef.getId()).removeAttr("tabindex"); } })
2.
重写enforceFocus方法(测试发现没有效果):
$.fn.modal.Constructor.prototype.enforceFocus = function() {};
总结
以上所述是小编给大家介绍的BootStrap模态框和select2合用时input无法获取焦点的解决方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
相关文章推荐
- bootstrap模态框和select2合用时input无法获取焦点
- bootstrap模态框modal和select2合用时input无法获取焦点
- 火狐下input焦点无法重复获取问题的解决方法
- select2和bootstrap模态框一起使用导致select2的input获取不到焦点问题
- 火狐下input焦点无法重复获取问题的解决方法
- bootstrap模态框和select2合用时input无法获取焦点
- 解决bootstrap模态框内输入框无法获取焦点
- bootstrap-modal:弹出modal时input的checked的状态无法改变 | | input获取焦点不生效
- 移动H5页面,Android手机下,input获取焦点弹出系统虚拟键盘时,挡住input解决方法
- ViewPager中嵌套Fragment中的EditText设置requestFocus无法获取焦点的解决方法
- .net 2.0 中对于非服务器端的input元素 type为file后台无法获取的问题的解决方法
- EditText和ScrollView共存,无法获取焦点,不能滚动的解决方法
- 解决searchView获取焦点时无法退出,拦截onkeyDown方法
- 当EditText被视图(按钮等)挡住无法获取焦点的解决方法
- bootstrap模态框input不能获取焦点并编辑【转】
- Quill编辑器IOS下无法获取焦点的解决方法
- bootstrap 的模态框无法获取焦点
- 解决动态添加input无法获取焦点事件
- Android listview 的 item 点击无效(无法获取焦点)的解决方法
- Android ListView 中子控件无法获取焦点的解决方法(主要针对键盘操作)