在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無法獲取焦點的解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com