我們寫頁面通常會遇到這種情況,一個模塊很多頁面都用到,那么我們為了方便就會單獨寫到一個頁面,然后引入進去,我知道的有三種:
1、用標簽<iframe></iframe>
例:
<iframe align="center" height="570" src="lib/sideBarL.html" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
iframe有自己默認的高度,如果你引入的頁面高度超出他默認的高度會超出隱藏,所以,要加上height="";
2、用標簽<object></object>
例:
<object data="lib/sideBarL.html" type="text/x-scriptlet" height="570"></object>
object也有自己的默認高度,如果你引入的頁面高度超出他默認的高度,引入部分會出現縱向滾動條,這個就很影響頁面美觀了,所以也是要加上height="";
3、div+$(“document”).load(“b.html”);
例:
<div class="sidebar"></div>
$('.sidebar').load('lib/sideBarL.html');
需要注意的是,這個div里面必須是空的,里面沒有任何元素,如果里面有其他的標簽,那么你引入的html會替換原來存在的內容。
好啦,就到這里。