用JavaScript编万年历 谁能给我解释一下这段代码

2025-02-06 05:39:33
推荐回答(3个)
回答1:

text+=str 等效于 text=text+str;

将字符串拼接起来。
// create first row of table to set column width and specify week day
创建表格的第一行来设置表格的列数,区别一个星期的每一天。

text += ''
for (var dayNum = 0; dayNum < 7; ++dayNum) {
text += openCol + weekDay[dayNum] + closeCol
}
text += ''

// declaration and initialization of two variables to help with tables
声明和初始化 2个变量

var digit = 1
var curCell = 1

lastDate 一个月的最后一天
firstDay一个月的第一天
2个想减得到一个月的天数 除去 7 的一个月有几周, 就有几行。

for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
text += ''
for (var col = 1; col <= 7; ++col) {
if (digit > lastDate)//日期大于最后一天 循环停止
break
if (curCell < firstDay) {//日期小于 第一天 内容为空
text += '';
curCell++
} else {//日期大于等于 第一天
if (digit == date) { // current cell represent today's date // 今天的日期 特别显示
text += ''
text += ''
text += '' + digit + ''
text += '
'
text += ''
text += '

' + getTime() + '
'
text += '
'
text += ''
} else
text += '' + digit + ''
digit++

关闭table标签
// close all basic table tags
text += ''
text += ''

}
}
text += ''
}

回答2:

只为经验

回答3:

我也没写过 就用第三方了!my97