在bootstrap的模態(tài)框里使用select2插件,會(huì)導(dǎo)致select2里的input輸入框沒有辦法獲得焦點(diǎn),沒有辦法輸入.
解決方法:
1.
把頁(yè)面中的 tabindex="-1" 刪掉(測(cè)試成功):
<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方法里面做處理,主要原理就是因?yàn)閎ootstrap的tabindex='-1',占用了select2的tabindex='0',腳本做處理 模態(tài)框顯示出來(lái)后,將模態(tài)框的tabindex屬性刪掉
BootstrapDialog.show({ onshown: function (dialogRef) { $("#"+dialogRef.getId()).removeAttr("tabindex"); }})2.
重寫enforceFocus方法(測(cè)試發(fā)現(xiàn)沒有效果):
$.fn.modal.Constructor.prototype.enforceFocus = function() {};總結(jié)
以上所述是小編給大家介紹的BootStrap模態(tài)框和select2合用時(shí)input無(wú)法獲取焦點(diǎn)的解決方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VeVb武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答