[英]load content of blog post in html file into template then into index file
我有一个HTML文件,其中包含博客文章内容以及另一个HTML文件中div的模板。
我只想获取博客文章内容并将其粘贴到博客文章模板主体中,并将其加载到索引html文件中。
内容html文件
<h1>Computer Science In Today</h1>
<p> body </p>
帖子模板
<div class="blog-post-type-1">
<div class="header"></div>
<div class="blog-post-content">
</div>
<div class="footer">
<img src="bg.png"/>
<img src="fgg.png"/>
<img src="background.png"/>
</div>
</div>
index.html文件
<body>
<div class="wraper">
<div class="all-blog-post">
</div>
</div>
</body>
我想在所有博客文章部分中添加博客文章。 我知道document.getElementById('all-blog-post').innerHTML
,但是我不知道如何获取内容并将其放入模板中,因此所有内容都应该在all-blog-post部分中。 我该怎么做或有可能做到? 实际上,这样做有意义吗? 如果没有,我该怎么办?
如果我是你,我会扭转你采取的步骤。 首先,在content.html顶部的内容上方需要一个包装器,使其看起来像这样:
<div class='content-class'>
<h1>Computer Science In Today</h1>
<p> body </p>
</div>
之后,您将要使用jquery加载功能将html插入到index.html中:
$(document).ready(function){
$('.all-blog-post').load('place-path-here/content.html');
}
一旦完成,您将需要将博客数据放入正确的包装中,这样整个jquery调用将如下所示:
$(document).ready(function){
$('.all-blog-post').load('place-path-here/content.html');
}
$(document).on('load', '.blog-post-content', function(){
var blog-post-content = $('.content-class').html();
$(this).append(blog-post-content);
});
希望这样的事情应该可行,减去一些可能的语法错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.