javascript跨架構顯示div,javascript架構div
項目中碰到需要跨架構顯示div的問題,百度了一下,搜集了一下群眾的智慧,特整理出下面這個例子,先看看:
本例共有4個頁面:
index.html
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style>.popDiv{position:absolute;float:left;width:300px;height:300px; background-color:#f7f7f7;top:50;left:25;display:none;z-index:2;}</style></head> <body> <div id='popId' class='popDiv'>the test div float over iframe.</div> <iframe src="frame.html" width=100% height=100% marginwidth=0></iframe> </body> </html>
frame.html
<frameset rows="74,*" cols="*" style="z-index:1"> <frame src="frame-top.html" style="z-index:1"> <frame src="frame-main.html" style="z-index:1"> </frameset><noframes></noframes>
frame-top.html
<a href="#" onclick="top.document.getElementById('popId').style.display='block'">show div</a>
frame-main.html
I'm main frame
頁面建立好,直接開啟index.html即可看到效果。具體原理就是通過在父版面設定好div,從frame內部調用父頁面的div來顯示