多個html怎么導入相同的頭部導航


1. iframe 包含法。
頁頭和頁尾分別做成一個頁面,然后通過iframe嵌入到調用的頁面。這種方法在頁頭頁尾高度固定的時候比較適用,因為當頁頭頁尾高度不固定時,需要iframe根據頁面內容自適應高度,比較麻煩。
簡單代碼結構示例:
<html>
<head>
<title>頁面</title>
<style type="text/css">
.page{width:950px;margin:0 auto;}
</style>
</head>
<body>
<div class="page">
<iframe frameboder="0" scrolling="no" width="100%" height="80" src="head.html"></iframe>
<div>頁面內容</div>
<iframe frameboder="0" scrolling="no" width="100%" height="80" src="foot.html"></iframe>
</div>
</body>
</html>
2. js包含法
頁頭和頁尾改成外接js的形式,通過documen.write輸出或其它js的輸出的方法。這種方法在頁頭頁尾需要修改時,不利於修改,也不好還原原先的html結構。
<html>
<head>
<title>頁面</title>
<style type="text/css">
.page{width:950px;margin:0 auto;}
</style>
</head>
<body>
<div class="page">
<script type="text/javascript" href="head.js"></script>
<div>頁面內容</div>
<script type="text/javascript" href="foot.js"></script>
</div>
</body>
</html>
3. shtml方法
運用服務端的包含方法,只需在頁面中使用服務端包含命令<!--# include file="文件名稱" -->,在被調用的頁面嵌入頁頭和頁腳即可。但此方法需要服務端支持ssi(server side include 服務端包含)功能。
<html>
<head>
<title>頁面</title>
<style type="text/css">
.page{width:950px;margin:0 auto;}
</style>
</head>
<body>
<div class="page">
<!--#include file="head.html" -->
<div>頁面內容</div>
<!--#include file="foot.html" -->
</div>
</body>
</html>


免責聲明!

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



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