时间:2021-05-28
复制代码 代码如下:
var StartYear = 1980;
var EndYear = 2500;
function MonthAndDay()
{
this.initDDL = function(objYear,objMonth,objDay,hidYear,hidMonth,hidDay)
{
this.init(objYear,objMonth,objDay,hidYear,hidMonth,hidDay);
this.SelectChange(objYear,objMonth,objDay,hidYear,hidMonth,hidDay);
}
this.init = function(objYear,objMonth,objDay,hidYear,hidMonth,hidDay)
{
var year = document.getElementById(objYear);
var month = document.getElementById(objMonth);
var day = document.getElementById(objDay);
var me=this;
if(year.length == 1)
{
year.options[0] = new Option("不限","");
for(var i = StartYear; i < EndYear; i++)
{
year.options[year.length] = new Option(i,i);
}
}
me.yearOptionsChange(document.all[objYear].value,objYear,objMonth,objDay);
me.monthOptionsChange(document.all[objYear].value,document.getElementById(objMonth).value,objDay);
}
this.yearOptionsChange = function(selectValue,objYear,objMonth,objDay)
{
var month = document.getElementById(objMonth);
var day = document.getElementById(objDay);
var me=this;
month.length = 0;
day.length = 0;
month.options[0]=new Option("不限",'');
day.options[0]=new Option("不限",'');
if(selectValue == "")
{
return ;
}
for(var i = 1; i < 13; i++)
{
month.options[month.length] = new Option((i < 10 ? ("0" + i) : i),i);
}
me.monthOptionsChange(document.getElementById(objYear).value,document.getElementById(objMonth).value,objDay);
}
this.monthOptionsChange = function(yearSelectValue,monthSelectValue,objDay)
{
var day = document.getElementById(objDay);
var endDay;
day.length = 0;
day.options[0]=new Option("不限",'');
if(monthSelectValue == "")
{
return;
}
if((parseInt(yearSelectValue) % 400 == 0) || (parseInt(yearSelectValue) % 4 == 0 && parseInt(yearSelectValue) % 100 != 0))
{
if(parseInt(monthSelectValue) == "2")
{
endDay = 29;
}
}
else
{
if(parseInt(monthSelectValue) == "2")
{
endDay = 28;
}
}
switch(parseInt(monthSelectValue))
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
endDay = 31;
break;
case 4:
case 6:
case 9:
case 11:
endDay = 30;
break;
}
for(var i = 1; i <= endDay; i++)
{
day.options[day.length] = new Option((i < 10 ? ("0" + i) : i),i);
}
}
this.SelectChange = function(objYear,objMonth,objDay,hidYear,hidMonth,hidDay)
{
var year = document.all[objYear];
var month = document.all[objMonth];
var day = document.all[objDay];
var me = this;
year.onchange = function()
{
me.yearOptionsChange(this.options[this.selectedIndex].value,objYear,objMonth,objDay);
document.all[hidYear].value = this.options[this.selectedIndex].value;
document.all[hidMonth].value = "";
document.all[hidDay].value = "";
}
month.onchange = function()
{
me.monthOptionsChange(document.all[hidYear].value,this.options[this.selectedIndex].value,objDay);
document.all[hidMonth].value = this.options[this.selectedIndex].value;
document.all[hidDay].value = "";
}
day.onchange = function()
{
document.all[hidDay].value = day.selectValue;
}
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例为大家分享了js实现日期联动选择的相关代码,适用于生日的选择,供大家参考,具体内容如下实现目标:年月日三个select输入框,以及一个hidden的in
一、简介编写一个会动的日历,日历上面有年月日,周几,时分秒,效果如下:年月日,周几,时分秒都会随着系统时间的走动而改变二、代码Document*{margin:
本文实例介绍了JavaScript时间操作之级联日期选择操作的详细代码,分享给大家供大家参考,具体内容如下效果图:具体代码:年月日星期级联for(i=1970;
核心代码/**获得时间差,时间格式为年-月-日小时:分钟:秒或者年/月/日小时:分钟:秒*其中,年月日为全格式,例如:2010-10-1201:00:00*返回
一、django中数据模型关于时间字段的认识1、DateField:可以记录年月日,映射到数据库是date类型2、DateTimeField:可以记录年月日时分