bootstrap modal與select2使用沖突解決


今天發現項目使用bootstrap modal 與 jquery select2 結合時發現select2不起作用,點擊select框不顯示選項,查閱資料后發現是因為modal層遮擋了select2的選擇層

下面是解決方案(親測),分兩步

 

1. select2 加入 dropdownParent 屬性,設置父元素modal

$(".select2-demo").select2({
    dropdownParent:$("#Modal-demo")
});

2. css設置 讓select2的選擇彈出層位於最上層,否則將被modal遮擋住


.select2-drop {
        z-index: 10050 !important;
    }
 
    .select2-search-choice-close {
        margin-top: 0 !important;
        right: 2px !important;
        min-height: 10px;
    }
 
        .select2-search-choice-close:before {
            color: black !important;
        }
    /*防止select2不會自動失去焦點*/
    .select2-container {
        z-index: 16000 !important;
    }
 
    .select2-drop-mask {
        z-index: 15990 !important;
    }
 
    .select2-drop-active {
        z-index: 15995 !important;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM