使用Javascript和CSS生成博客文章
Generate Blogposts using Javascript and CSS
我想使用Javascript生成简单的博客文章。我的功能如下:
function generatePost(title, time, text) {
var div = document.createElement("div");
div.className = "content";
document.getElementById("postcontainer").appendChild(div);
}
如果在HTML文档中使用我的函数,则结构应该如下所示:
<div id="postcontainer">
<div class="content"> /*This is the actual post*/
<h3>title<span>time</span></h3>
<p>text</p>
</div>
<div class="content">
<h3>title2<span>time2</span></h3>
<p>text2</p>
</div>
</div>
我不知道如何在类/ID不相互干扰的情况下生成多个帖子。知道吗?提前感谢!
这里有一个非常简单的解决方案。为每个内容div添加一个id,其中包括一个唯一的帖子id。在本例中,是帖子编号。
var postCount = 0;
function generatePost(title, time, text) {
var div = document.createElement("div");
div.className = "content";
div.id = "blog_" + postCount
postCount++;
document.getElementById("postcontainer").appendChild(div);
}
相关文章:
- 我怎么能只用Javascript(AJAX)编写其中一篇文章呢
- 如何将 javascript 添加到 SharePoint 2013 文章页面
- 如何在忽略文章(a,an,the)的情况下对javascript数组进行排序
- 用于调整博客文章中照片大小的JavaScript
- 使用Javascript和CSS生成博客文章
- 我读到了关于javascript函数/原型和(fiddle提供)的文章
- 在Wordpress文章中插入JavaScript
- JavaScript引擎开发书籍或文章
- 基本无限滚动/延迟加载博客文章与纯JavaScript
- 在前面的文章中没有提到的情况下,在Javascript中对正则表达式求反
- 如何将JavaScript数组作为文章的一部分传递给ASP.NETMVC操作
- 博客文章的文本*拦截器* ?(javascript ?php ?)
- 另一篇关于在Javascript方法中调用变量的文章
- Wordpress javascript在文章中的相对路径
- 将文章存储在javascript变量中
- Javascript没有'我不做ajax文章
- Joomla文章中的表单验证javascript不起作用
- 用于文章的PHP或JavaScript表示库
- 提取一篇文章的主要内容(JavaScript)