怎么在html中include一个文件内容

别说用什么框架等东西!!
找了好多,不是很理想
有什么代码也能让静态页来读取一个文件吗?

在html中include一个文件,方法不只一种,在以前我只会使用iframe来引用,后来发现了另外的几种方法,本人觉得第三种方式较好:
1.IFrame引入,看看下面的代码

[代码] <IFRAME NAME="content_frame" width=100% height=30 marginwidth=0 marginheight=0 SRC="import.htm" ></IFRAME>
你会看到一个外部引入的文件,但会发现有一个类似外框的东西将其包围,可使用
[代码] <iframe name="content_frame" marginwidth=0 marginheight=0 width=100% height=30 src="import.htm" frameborder=0></iframe>
但你会发现还会有点问题,就是背景色不同,你只要在引入的文件import.htm中使用相同的背景色也可以,但如果你使用的是IE5.5的话,可以看看这篇关于透明色的文章 如果想引入的文件过长时不出现滚动条的话在import.htm中的body中加入scroll=no

2.<object>方式

[代码] <object style="border:0px" type="text/x-scriptlet" data="import.htm" width=100% height=30></object>

3.Behavior的download方式
[代码]
<span id=showImport></span>
<IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
<script>
function onDownloadDone(downDate){
showImport.innerHTML=downDate
}
oDownload.startDownload('import.htm',onDownloadDone)
</script>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-10-16
把你要写的.html文件编译成js文件然后加入<script src="**.js" type="text/javascript"></script>到你要添加的代码部分,其中文件的路径最好是绝对路径。
第2个回答  推荐于2017-05-21
function include(url)
{
$.get(url,function(data){document.write(data);})
}

<script>include('top.html')</script>

前提引入jquery
第3个回答  2015-08-24

include是SSI(Server Side Include),在html中不支持include,你可以使用iframe标签。

<iframe   frameborder=0   border=0   width=300   height=300   src="b.htm" mce_src="b.htm"></iframe>

第4个回答  2013-07-27
用XMLHttpRequest || XMLHTTP
或者
<script type="text/javascript" src="xx.html">
相似回答