我有一个纯HTML页面,例如sample.html。我需要将此HTML包含到另一个纯HTML中,例如Orginal.html。如何做到这一点?在我的sample.html中有一个标题图像。它应该出现在Orginal.html页面的顶部。
我有一个纯HTML页面,例如sample.html。我需要将此HTML包含到另一个纯HTML中,例如Orginal.html。如何做到这一点?在我的sample.html中有一个标题图像。它应该出现在Orginal.html页面的顶部。
在纯HTML中,您无法做到这样的事情,除非使用框架或iframe元素。但最好手动合并它们...
<body>
<h1>This is original page</h1>
<p>Some content on original page.</p>
<iframe src="sample.html" width="600" height="300"></iframe>
</body>
您可以使用JavaScript将一个文档中的HTML加载到另一个文档中。使用jQuery工具包可以轻松完成此任务:
$("The ID of a container (a div element for instance) in which you want to load
the contents of a HTML file").load("path to html file you want to load");
<div id="inserthere" />
$(function ()
{
$("#inserthere").load("loadme.html"); // Load the contents of loadme.html
// and stuff it in the div with the
// ID of "inserthere"
});