Javascript 如何将html内容动态插入到现有html文档中?
比如说,我有一个名为index.html的html文档。 另外,我还有另一个名为blog_content.html的html文档 我想要的是,当客户端请求index.html时,可以将动态数量的blog_content.html加载到index.html中。此外,blog_content.html中的内容也会动态生成 blog_content.html可能看起来像:Javascript 如何将html内容动态插入到现有html文档中?,javascript,jquery,html,web,Javascript,Jquery,Html,Web,比如说,我有一个名为index.html的html文档。 另外,我还有另一个名为blog_content.html的html文档 我想要的是,当客户端请求index.html时,可以将动态数量的blog_content.html加载到index.html中。此外,blog_content.html中的内容也会动态生成 blog_content.html可能看起来像: <div class="a_blog_container" id="${article.id}"> <h2>
<div class="a_blog_container" id="${article.id}">
<h2>${article.title}</h2>
<h3>${article.metadata.date}</h3>
<div class="a_blog_content">
<p>this is test content</p>
</div>
<p class="article_foot"><span>赞(${article.additional.up})</span><span> |
</span><span>阅读(${article.additional.read})</span></p>
${article.title}
${article.metadata.date}
这是测试内容
赞(${article.additional.up})|
阅读(${article.additional.read})
其中,$
之类的内容是占位符,每当任何后端引擎呈现文档(例如Spring)时,都会动态地为其分配值
您对上述要求有何建议
=========一些补充资料=========
对于前端,我选择JQuery;
至于后端,它是Spring。现在回头看看这个问题,我发现它是一个愚蠢的问题:)。
正如你们所说,我设置了一个rest服务器来提供博客内容。在客户端,它向服务器发送内容请求。使用从服务器获得的内容,JavaScripts然后将内容组装成可读的元素。现在一切都好了。非常感谢大家的帮助。一个词
Nodejs
为什么博客内容条目列在HTML表单中,而不是数据库或文件存储系统中?确切地说,博客内容是在哪里创建的?您可以通过服务器端包含提供两个不同的网页。但是使用.html页面作为数据存储?ugh.use templatesjs()“后端引擎将呈现文档”-如果博客文章内容呈现在服务器端,那么在客户端,这将是非常简单的Ajax代码,例如jQuery的.load()
method.对于前端堆栈,我建议使用vuejs
文件index
和blog
是日常填充的模板。。对于后端使用node
、php
、python
等,您更喜欢什么。我认为在REST服务器上学习这项任务将在将来对您有所帮助。