由Javascript实现的页面日历_时间日期
程序员文章站
2022-06-06 17:37:57
...
效果图:
CSS代码:
脚本代码:
");
var press_tag;
function changecal(action,year,month)
{
var strcal;
switch(action)
{
case "nextmonth":
if(month==11)
{
month = 1;
year = year*1 + 1;
}else{
month = month*1 + 2;
}
strcal = "> ";
break;
case "premonth":
if(month==0)
{
month = 12;
year = year*1 - 1;
}
strcal = " ";
break;
case "nextyear":
year = year*1 + 1;
month = month*1 + 1;
strcal = ">>";
break;
case "preyear":
year = year*1 - 1;
month = month*1 + 1;
strcal = "";
break;
default:;
}
strcal = " " + strcal + " ";
return(strcal);
}
function calender(cyear,cmonth)
{
var d,d_date,d_day,d_month;
//定义每月天数数组
var monthdates = ["31","28","31","30","31","30","31","31","30","31","30","31"]
d = new Date();
d_year = d.getYear(); //获取年份
//判断闰月,把monthdates的二月改成29
if (((d_year % 4 == 0) && (d_year % 100 != 0)) || (d_year % 400 == 0)) monthdates[1] = "29";
if ((cyear != "" ) || (cmonth != ""))
{
//如果用户选择了月份和年份,则当前的时间改为用户设定
d.setYear(cyear);
d.setMonth(cmonth-1);
d.setDate(1);
}
d_month = d.getMonth(); //获取当前是第几个月
d_year = d.getYear(); //获取年份
d_date = d.getDate(); //获取日期
//修正19XX年只显示两位的错误
if(d_year//===========输出日历===========
var str;
str = "";
"
document.getElementById("calenderdiv").innerHTML = "
}
//调用函数
calender("","")
//-->
CSS代码:
复制代码 代码如下:
脚本代码:
复制代码 代码如下:
var press_tag;
function changecal(action,year,month)
{
var strcal;
switch(action)
{
case "nextmonth":
if(month==11)
{
month = 1;
year = year*1 + 1;
}else{
month = month*1 + 2;
}
strcal = "> ";
break;
case "premonth":
if(month==0)
{
month = 12;
year = year*1 - 1;
}
strcal = " ";
break;
case "nextyear":
year = year*1 + 1;
month = month*1 + 1;
strcal = ">>";
break;
case "preyear":
year = year*1 - 1;
month = month*1 + 1;
strcal = "";
break;
default:;
}
strcal = " " + strcal + " ";
return(strcal);
}
function calender(cyear,cmonth)
{
var d,d_date,d_day,d_month;
//定义每月天数数组
var monthdates = ["31","28","31","30","31","30","31","31","30","31","30","31"]
d = new Date();
d_year = d.getYear(); //获取年份
//判断闰月,把monthdates的二月改成29
if (((d_year % 4 == 0) && (d_year % 100 != 0)) || (d_year % 400 == 0)) monthdates[1] = "29";
if ((cyear != "" ) || (cmonth != ""))
{
//如果用户选择了月份和年份,则当前的时间改为用户设定
d.setYear(cyear);
d.setMonth(cmonth-1);
d.setDate(1);
}
d_month = d.getMonth(); //获取当前是第几个月
d_year = d.getYear(); //获取年份
d_date = d.getDate(); //获取日期
//修正19XX年只显示两位的错误
if(d_year//===========输出日历===========
var str;
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 += " | ||||||
Su | Mo | Tu | We | Th | Fr | Sa |
"; | " + (count - firstspace) + " | ";" + (count - firstspace) + " | ";||||
"; | ||||||
www.sugood.cn |
document.getElementById("calenderdiv").innerHTML = "
" + str + "
"; }
//调用函数
calender("","")
//-->
上一篇: sql查询问题