找到一种方法可以做到这一点从html5rocks,但它远远不可读。这是理想的方式:
<body>
<include src="header.html"/>
</body>
这是它是如何通过HTML5进口实施:
<head>
<link rel="import" href="header.html">
</head>
<body>
...
<script>
document.body.appendChild(
document.querySelector('link[rel="import"]')
.import
.querySelector('body')
.cloneNode(true));
</script>
</body>
注:
- 不清楚如何选择包括如果两个
header.html
和footer.html
是否有
querySelector('body')
需要避免Uncaught HierarchyRequestError: Failed to execute 'appendChild' on 'Node': Nodes of type '#document' may not be inserted inside nodes of type 'BODY'.
- 不清楚如何插入
<body>
标签内容,而不标签本身
- HTML5进口不工作在Firefox(38)http://caniuse.com/#feat=imports =/
你看http://www.w3schools.com/ tags/tag_iframe.asp – Garry
这是实验性的。你可能不得不采取像http://api.jquery.com/load/ –