当前位置:Gxlcms > JavaScript > 由Javascript实现的页面日历_时间日期

由Javascript实现的页面日历_时间日期

时间:2021-07-01 10:21:17 帮助过:11人阅读

效果图:

CSS代码:
代码如下:



脚本代码:
代码如下:

输出日历===========
var str;
str = "";
str += "";
str += "";
str += "";
var firstday,lastday,totalcounts,firstspace,lastspace,monthdays;
//需要显示的月份共有几天,可以用已定义的数组来获取
monthdays = monthdates[d.getMonth()];
//设定日期为月份中的第一天
d.setDate(1);
//需要显示的月份的第一天是星期几
firstday = d.getDay();
//1号前面需要补足的的空单元格的数
firstspace = firstday;
//设定日期为月份的最后一天
d.setDate(monthdays);
//需要显示的月份的最后一天是星期几
lastday = d.getDay();
//最后一天后面需要空单元格数
lastspace = 6 - lastday;
//前空单元格+总天数+后空单元格,用来控制循环
totalcounts = firstspace*1 + monthdays*1 + lastspace*1;
//count:大循环的变量;f_space:输出前空单元格的循环变量;l_space:用于输出后空单元格的循环变量
var count,flag,f_space,l_space;
//flag:前空单元格输完后令flag=1不再继续做这个小循环
flag = 0;
for(count=1;count<=totalcounts;count++)
{
//一开始flag=0,首先输出前空单元格,输完以后flag=1,以后将不再执行这个循环
if(flag==0)
{
if(firstspace!=0)
{
for(f_space=1;f_space<=firstspace;f_space++)
{
str += "";
if(f_space!= firstspace) count++;
}
flag = 1;
continue;
}
}
if((count-firstspace)<=monthdays)
{
//输出月份中的所有天数
curday = d_year+","+(d_month*1+1)+","+(count - firstspace)+"|"
linkday = d_year+","+(d_month*1+1)+","+(count - firstspace)
var today = new Date();
if( (d_year == today.getYear()) && (d_month == today.getMonth()) && ((count-firstspace) == today.getDate()) )
{
//将本地系统中的当前天数高亮
str += "";
}else{
//不用高亮的部分,没有日志
str += "";
}
if(count%7==0)
{
if(count{
str += "
";
}else{
str += "";
}
}
}else{
//如果已经输出了月份中的最后一天,就开始输出后空单元格补足
for(l_space=1;l_space<=lastspace;l_space++)
{
str += "";
if(l_space!= lastspace) count++;
}
continue;
}
}
str += "
"
str += changecal("preyear",d_year,d_month)
str += changecal("premonth",d_year,d_month)
str += d_year + " - " + (d_month*1+1)
str += changecal("nextmonth",d_year,d_month)
str += changecal("nextyear",d_year,d_month)
str += "
SuMoTuWeThFrSa
" + (count - firstspace) + "" + (count - firstspace) + "
www.sugood.cn
"
document.getElementById("calenderdiv").innerHTML = "
" + str + "
";
}
//调用函数
calender("","")
//-->

人气教程排行