[英]how to separate header footer and sidebar in a html template with jquery/ javascript
我有一个带有页眉,页脚和侧边栏的模板; 我想将它们分成单独的文件,并将其包含在主模板中。 以前我使用过PHP,通过include()
或required()
函数很容易做到这一点,但是由于我使用的是node.js而不是PHP,所以我不知道该怎么做。
<script>
$(document).ready(function (e) {
$( "#header" ).load( "header.html" );
$( "#sidebar" ).load( "sidebar.html" );
$( "#footer" ).load( "footer.html" );
});
</script>
您可以使用jQuery。
您可以使用W3schools库轻松实现此目的。
在您的HTML中添加此脚本
<script src="https://www.w3schools.com/lib/w3.js"></script>
调用w3.includeHTML()以包含HTML:
<script>
w3.includeHTML();
</script>
完整的例子
<!DOCTYPE html>
<html>
<script src="https://www.w3schools.com/lib/w3.js"></script>
<body>
<div w3-include-html="content.html"></div>
<script>
w3.includeHTML();
</script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.