bootstrap模態框和select2合用時input無法獲取焦點

更多內容: http://blog.yuhai.win

參考文獻:

http://blog.csdn.net/fireofjava/article/details/48414207
http://www.voidcn.com/blog/ynwso/article/p-296035.html
當bootstrap 模態框和select2配合使用的時候或出現 input 無法獲取焦點的問題

產生的原因:

Bootstrap registers a listener to the focusin event which checks whether the focused 
element is either the overlay itself or a descendent of it - if not it just refocuses on 
the overlay. With the select2 dropdown being attached to the body this effectively 
prevents you from entering anything into the the textfield.

You can quickfix this by overwriting the enforceFocus function which registers
 the event on the modal

解決辦法:


我這次解決的辦法就是把tabindex="-1"去掉就可以了

其他的解決辦法:

<script>

$(document).ready(function() {
  $("#select2insidemodal").select2({
    dropdownParent: "#myModal"
  });
});

</script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章