JavaScript写的日历中的一段代码,看不懂,求解释
发布网友
发布时间:2022-04-24 05:15
我来回答
共2个回答
热心网友
时间:2022-04-24 06:44
代码帮你解释下 后面问题没看懂
function newCalendar() {
var parseYear = parseInt(document.all.Year.options[document.all.Year.selectedIndex].value);
// 获取年月下拉框的值,生成一个日期
var newCal = new Date(parseYear, document.all.Month.selectedIndex, 1);
var day = -1;
var startDay = newCal.getDay(); //星期几
var daily = 0; // 生成日历时,不断++,输出日期到日历上的值
// 比如today = {year:2014,month:9,day:20};
if ((today.year == newCal.getFullYear()) && (today.month == newCal.getMonth()+1))
// 如果下拉框选择的年月值=现在年月(2014,9),则保存今天日期,比如现在是20号,生成日历时会将今天高亮显示
day = today.day;
var tableCal = document.all.calendar;
var intDaysInMonth = getDays(newCal.getMonth(), newCal.getFullYear()); //
for (var intWeek = 1; intWeek < tableCal.rows.length; intWeek++)
for (var intDay = 0; intDay < tableCal.rows[intWeek].cells.length; intDay++) {
var cell = tableCal.rows[intWeek].cells[intDay];
if ((intDay == startDay) && (0 == daily))
daily = 1; // 判断从星期几开始打印
//var nowtime = new getToday();
if (day == daily) //今天,调用今天的Class
{
cell.style.background = '#6699CC';
cell.style.color = 'yellow';
cell.style.fontWeight = 'bold';
} else if (intDay == 6) //周六
cell.style.color = 'green';
else if (intDay == 0) //周日
cell.style.color = 'red';
if ((daily > 0) && (daily <= intDaysInMonth)) {
cell.innerText = daily; //打印日期1,2,3...31
daily++;
} else
cell.innerText = "";
}
}
追问真是好人,谢了
热心网友
时间:2022-04-24 08:02
日历有专门的日历控件,很强大的,www.17sucai.com追问谢谢