html5中有没有像jsp include一样的函数?
类似的东西可以使用单个源自动添加到页面。
最佳答案
不,如果您需要此类行为,请使用服务器端语言,例如 PHP。如果您无法做到这一点,则必须使用 JavaScript 来“包含”另一个页面,方法是通过 AJAX 获取该页面,然后将其添加到 DOM。
PHP 示例:
<?php include 'header.html'; ?>
<h1>hi</h1>
<p>blah blah</p>
<?php include 'footer.html'; ?>
JS 示例 using jQuery :
<!doctype html>
<body>
static stuff
<div id="content"></div>
<script>
$('#content').load('content.html');
</script>
</body>
不要不要使用这样的 JS 解决方案。它将使页面无法被任何没有支持 JS 的浏览器(例如搜索引擎)的人使用。
关于java - jsp在html5中包含函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10087141/