解決div層被select下拉框遮蓋的問題

來源:互聯網
上載者:User

在IE裡,層DIV被下拉框SELECT遮蓋,這是IE的bug之一,原因在於select的優先順序別比div高。因此無論如何用css屬性z-index設定都沒用。

所以,解決的辦法有兩種

  • 在顯示div的時候隱藏所有select
  • 讓div裡的內容比select的優先順序還要高

第一種方法顯然比較麻煩,特別是當select比較多且位置不固定的時候,很容易將不該隱藏的也隱藏了。

第二鐘辦法更好一些。常用的優先順序比select高的HTML控制項有object和iframe,我選用了iframe比較好。

原理就是在div種加入一個iframe,然後把需要顯示的內容write到iframe的body中。

參考代碼如下:

var oIframe = document.createElement("<iframe name=/"oIframeFilter/" frameborder=/"0/"></iframe>")
if (oDivFilter.children.length != 0) oDivFilter.removeChild(oDivFilter.children(0));
oDivFilter.appendChild(oIframe);
window.frames[oIframe.name].document.write("<link rel=/"stylesheet/" href=/"/style/css.css/" type=/"text/css/">");
sBody = "<table><tr><td>哈哈哈哈</td></tr></table>";
window.frames[oIframe.name].document.write(sBody);

此外,還需要注意iframe的屬性allowTransparency就不能再用了,因為透明就讓iframe更高的優先順序失效了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.