我有一个模板,其中有页眉、页脚和侧边栏;我想将它们分成单独的文件并将它们包含在主模板中。以前我使用的是 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 来实现这一点。
关于javascript - 如何使用 jquery/javascript 在 html 模板中分离页眉页脚和侧边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48599466/