bootStrap模態框與select2合用時input不能獲取焦點
在bootstrap的模態框裏使用select2插件,會導致select2裏的input輸入框沒有辦法獲得焦點,沒有辦法輸入.
- 把頁面中的 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">
- 重寫enforceFocus方法:(測試可用)
保證他能被執行到就行
模態框內部滑動
不使用頁面的滾動條
css:給模態框設置overflow-y: hidden;即爲取消掉頁面滾動條的使用
#HelpModal{margin-top: 95px;height: 300px;overflow-y: hidden;}
添加滾動條,添加滾動條的位置不同效果不同
.modal-content {overflow: auto;max-height:300px;}
html:模態框最外層設置id屬性的overflow-y: hidden;,權重值高於自定義的.modal-open .modal類名設置的overflow-y: auto;
select選中跳轉
select2選中事件
$(".demo").on("select2:select",function(e){
console.log(e);
})
**跳轉到本頁面中指定位置 **
document.getElementById(‘uuuu’).scrollIntoView()
官網select2事件介紹