使用 jQuery:
<html>
<head>
<script src="jquery.js"></script>
<script>
$(function(){
$("#includedContent").load("b.html");
});
</script>
</head>
<body>
<div id="includedContent"></div>
</body>
</html>
使用没有 jQuery 的 JavaScript:
<html>
<body>
<script src="b.js"></script>
</body>
</html>
b.js:
document.write('\
\
<h1>This is my include file</h1>\
\
');
使用 PHP:
<?php include('b.html');?>
为此,您可能需要修改 Web 服务器上的 .htaccess 文件,以便可以在 .html 文件中解释 php。您应该在 .htaccess 文件中看到或添加它:
RemoveHandler.html
AddType application/x-httpd-php .php .html
带有服务端包含 (SSI):
<!--#include virtual="a.html" -->
使用 HTML5:
<object name="foo" type="text/html" data="foo.inc"></object>
或者:
<embed type="text/html" src="foo.inc">