提问人:Ayush Gour 提问时间:6/4/2022 更新时间:6/4/2022 访问量:11
如何在不重新加载整个页面的情况下更新页面上的特定重复 div(每次使用不同的数据)?
How to update a particular repetative div (with different data each time) on a page without reloading entire page?
问:
我正在使用 wordpress 并将最新帖子存档设置为首页。
我正在使用一个插件以“time ago”格式显示发布后的时间。
我希望在首页存档中分别为每个列出的帖子自动更新这个时间前的邮票。
这是页面的架构 -
<div id="posts">
<article class="post-1">
<div id="post-title">
TITLE
</div>
<div id="publish-date-time">
<div class="post-meta-data">
<div class="post-date-time">
30 seconds ago
</div>
</div>
</div>
</article>
<article class="post-2">
<div id="post-title">
TITLE
</div>
<div id="publish-date-time">
<div class="post-meta-data">
<div class="post-date-time">
30 seconds ago
</div>
</div>
</div>
</article>
</div>
现在我想在不重新加载页面的情况下为每篇文章更新带有时间前戳的 div。
我试过了——
$(article).each( funtion() {
setinterval( function() {
$(this).find("#publish-date-time").load(location.href + " #publish-date-time");
}, 60000);
return false;
但这只会在首页上的第一篇文章上添加各种时间戳,而不会做其他任何事情。
以我对 ajax、wordpress、jquery 和 Web 开发有限的了解,我只能猜测我需要 Ajax 来获取每个帖子的发布日期,然后通过 html 或文本将其提供给每个发布后的时间,但我不知道该怎么做。
帮助将不胜感激。
谢谢。
答: 暂无答案
评论