jQuery: update content every week (or long period of time)

后端 未结 1 1305
滥情空心
滥情空心 2021-01-15 16:27

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.

1条回答
  •  北海茫月
    2021-01-15 17:04

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

    (got the code from 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);
    });
    

    0 讨论(0)
提交回复
热议问题