在bootstrap的模态框里使用select2插件,会导致select2里的input输入框没有办法获得焦点,没有办法输入。怎么解决这个问题呢?下面小编给大家带来了bootstrap模态框和select2合用时input无法获取焦点的解决方法,一起看看吧
在bootstrap的模态框里使用select2插件,会导致select2里的input输入框没有办法获得焦点,没有办法输入.
解决方法:
把页面中的 tabindex=-1 删掉(测试成功):
<p id="mymodal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true">
<p class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="mymodallabel">panel</h3>
</p>
<p class="modal-body" style="max-height: 800px">
<p id="mymodal" class="modal hide fade" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true">
<p class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="mymodallabel">panel</h3>
</p>
<p class="modal-body" style="max-height: 800px">
可以在onshown方法里面做处理,主要原理就是因为bootstrap的tabindex='-1',占用了select2的tabindex='0',脚本做处理 模态框显示出来后,将模态框的tabindex属性删掉
bootstrapdialog.show({
onshown: function (dialogref) {
$("#"+dialogref.getid()).removeattr("tabindex");
}
})
重写enforcefocus方法(测试发现没有效果):
$.fn.modal.constructor.prototype.enforcefocus = function() {};
以上就是完美解决bootstrap模态框和select2合用时input无法获取焦点问题的详细内容。