BootStrap模態(tài)框和select2合用時input無法獲取焦點的解決方法
在bootstrap的模態(tài)框里使用select2插件,會導(dǎo)致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'
,腳本做處理 模態(tài)框顯示出來后,將模態(tài)框的tabindex屬性刪掉
BootstrapDialog.show({ onshown: function (dialogRef) { $("#"+dialogRef.getId()).removeAttr("tabindex"); } })
2.
重寫enforceFocus方法(測試發(fā)現(xiàn)沒有效果):
$.fn.modal.Constructor.prototype.enforceFocus = function() {};
總結(jié)
以上所述是小編給大家介紹的BootStrap模態(tài)框和select2合用時input無法獲取焦點的解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
用javascript實現(xiàn)的支持lrc歌詞的播放器
用javascript實現(xiàn)的支持lrc歌詞的播放器...2007-05-05JS實現(xiàn)動態(tài)生成html table表格的方法分析
這篇文章主要介紹了JS實現(xiàn)動態(tài)生成html table表格的方法,結(jié)合實例形式分析了javascript針對數(shù)組數(shù)據(jù)的讀取、遍歷以及動態(tài)生成相關(guān)操作技巧,需要的朋友可以參考下2018-07-07