[英]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.