html中静态包含公共部分
1、采用js方法
<body>
<div id="div"></div>
<script>
document.getElementById("div").innerHTML = '<object type="text/html" data="index.html" width="100%" height="100%"></object>';
</script>
</body>
<body> <div id="div"></div> <script> $("#div").load("index.html"); </script></body>
2、采用apache等服务器,使用include
apache默认不支持SSI,可以通过修改配置文件来使其支持
搜索AddType text/html .shtml的位置,打开以下注释
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
同时需要找到Options Indexes FollowSymLinks,在其后添上Includes
以上表示支持shtml的include命令,如果还想支持html,则需改为
AddType text/html .shtml .html
AddOutputFilter INCLUDES .shtml .html
使用办法:
建立A.html文件如下
<!DOCTYPE html><html><head><meta charset=utf-8><title>include</title></head><body> <!--#include file="B.html" --> </body> </html>
建立B.html文件如下
<div>我是被include包含进来的</div>
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。