jQuery:每周(或长时间)更新内容 [英] jQuery: update content every week (or long period of time)

查看:203
本文介绍了jQuery:每周(或长时间)更新内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说我不是一个强大的JavaScript/jQuery程序员,我用它做非常基本的事情,但是有时候像我这样的事情对我来说有点毛茸茸.

Let me start by saying that I'm not a power-JavaScript/jQuery programmer, I do very basic things with it, yet sometimes things get a little hairy for me, like this one.

我的案子:

我有一份推荐清单(大约20条),我需要每周(星期一)进行更新.

I have a list of testimonials (around 20) and every week (Mondays) I need to updated them.

我的问题:

我手动更新它们.我的意思是,我打开Dreamweaver,更新相应证明书编号的jQuery代码,然后上传到服务器.

I update them manually. I mean, I open Dreamweaver, update the jQuery code for the corresponding testimonial number, and upload to server.

我需要什么:

一种使此过程自动化的方法...尽可能最佳.

A way to have this be automated... as best as possible.

HTML推荐书:

<body>
<div class="quotes-container quote-1">
  <div class="quote">Testimonial...</div>
  <div class="author">Author</div>
</div>
<div class="quotes-container quote-2">
  <div class="quote">Testimonial...</div>
  <div class="author">Author</div>
</div>
<div class="quotes-container quote-3">
  <div class="quote">Testimonial...</div>
  <div class="author">Author</div>
</div>
...
</body>

我的jQuery用来更改个人推荐:

$(function(){ $('#quotes-wrapper').load('/static-files/testimonials.html div.quote-1'); });

$(function(){ $('#quotes-wrapper').load('/static-files/testimonials.html div.quote-1'); });

如您所见,我要做的就是手动将 div.quote-1 更改为 div.quote-2 div.quote-3 等.

As you can see all I need to do is to manually change div.quote-1 to div.quote-2 or div.quote-3 and so on.

但是我知道有一种方法可以让jQuery在每个星期一(或星期二,或我为此选择的任何一天)动态地"更改这些推荐,并且不必随时提醒自己,不要忘记更改每个星期一的推荐信.

But I know there's got to be a way to have jQuery change these testimonials 'dynamically' every Monday (or Tuesday, or any day I choose for that matter), and not have to keep reminders around to not forget to change the testimonials every Monday.

有什么想法可以实现吗?

Any ideas how can this be accomplished?

谢谢.

推荐答案

您可以找出一年中的第几周来选择div:

You could find out the week of year to select the div:

(从 http://javascript.about.com/library/blweekyear中获取代码. htm )

Date.prototype.getWeek = function() {
  var onejan = new Date(this.getFullYear(),0,1);
  return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
}
$(function(){
  var today = new Date();
  var weekno = today.getWeek();
  $('#quotes-wrapper').load('/static-files/testimonials.html div.quote-'+weekno);
});

这篇关于jQuery:每周(或长时间)更新内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆