簡體   English   中英

如何在 node.js 中包含 HTML 文件

[英]How to include a HTML file with node.js

所以,我有一個加載index.html文件的server.js文件。

問題是,有沒有辦法在index.html中導入另一個html文件。

為簡化起見,假設我有一個名為footer.html的 html 文件,我想將它導入到我的index.html 中 我該怎么做?

您可以內聯發送您的 html,或使用 'fs' 模塊讀取 html 文件並發送它。

但是最好使用模板引擎,比如ejs、handlebar等。

有關更多信息, 參閱本教程https://scotch.io/tutorials/use-ejs-to-template-your-node-application

您可以使用 jquery 來完成此操作。

 <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(function(){ $("#includedContent").load("index.html"); }); </script> </head> <body> <div id="includedContent"></div> </body> </html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM