javascript - 如何获取本周是第几周而且需要得到之前有多少周并创建列表?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <code> function theWeek() {
var totalDays = 0;
now = new Date ();
years = now.getYear()
if (years < 1000)
years += 1900
var days = new Array(12);
days[0] = 31;
days[2] = 31;
days[3] = 30;
days[4] = 31;
days[5] = 30;
days[6] = 31;
days[7] = 31;
days[8] = 30;
days[9] = 31;
days[10] = 30;
days[11] = 31;
if (Math. round (now.getYear() / 4) == now.getYear() / 4) {
days[1] = 29
} else {
days[1] = 28
}
if (now.getMonth() == 0) {
totalDays = totalDays + now. getDate ();
} else {
var curMonth = now.getMonth();
for ( var count = 1; count <= curMonth; count ++) {
totalDays = totalDays + days[ count - 1];
}
totalDays = totalDays + now. getDate ();
}
var week = Math. round (totalDays / 7);
return week;
}
$( '#week' ).text(theWeek());
</code>
|
以上获取到了本周是今年第几周,如何计算前面有多少周并且创建如下的DOM结构?
1 2 3 4 5 6 | <code><ul id= "before-week" >
............
<li>第29周</li>
<li>第30周</li>
<li>第31周(本周)</li>
</ul></code>
|