这个月的决定,因为有太多的决策标准,如果其他的话会大大降低
性能,建议使用开关语法。
代码如下:
复制代码代码如下所示:
getdays:
功能(年、月){
一天= { 31,28 | 29,31,30,31,30,31,31,30,31,30,31 } /无功;
二月/日数据
处理数
无功feddays =年% 4 = = 029:28,
回天=;
VaR月=月< 10month = 0+月:month.tostring();
开关(月){
01案例:
2003案例:
05'case:
新加坡的
情况:
08的案例:
例10':
例12:回天= 31;突破;
发行的情况:
国际的情况:
年的情况:
例11:回天= 30;突破;
例102:回天= feddays;打破;
}
返回天;
}
完整源代码:
复制代码代码如下所示:
作者:laoguoyong / *
这个
日期三联动,范围选择
这个
参数 * {串}
目标:#年,#月,#天;年、月、日,ID
* {串}范围:'2013-02-032019-09-21;范围,
正确的格式是XXXX年XX月XX
要
保存代码,请传递正确的日期范围参数。
-
错误演示:
(1)范围:'2013-02-032019-9-21'is错,注意日期格式
(2)范围:'2013-02-03'is错误,请
输入完整的值的范围
(3)范围:'2013-02-032016-02-30'is不对,二月没有30天
(3)范围:'2013-02-032011-02-30'is错误和范围是错误的
*
* /
功能gysetdate(OPT){
/ /元
VaR指标= opt.targets.split(',');
this.eyear = this.getid(目标{ 0 }。片(1));
this.emonth = this.getid(目标{ 1 }。片(1));
this.eday = this.getid(目标{ 2 }。片(1));
如果(!这|咿呀|!这emonth | |!这个获奖)返回;
范围
VAR r = opt.range.indexof(','),
astarts = opt.range.slice(0,R),(-)。分裂 / /:{亿万,2005,20'}
aends = opt.range.slice(R + 1,选择范围。长度)。Split(-); / /:{ '2018,08、20'}
数字
类型 this.startyear = parseInt(astarts { 0 },10);
this.startmonth = parseInt(astarts { 1 },10);
this.startday = parseInt(astarts { 2 },10);
this.endyear = parseInt(aends { 0 },10);
this.endmonth = parseInt(aends { 1 },10);
This.endDay = parseInt (aEnds{2}, 10);
This.init();
}
gysetdate.prototype = { {
init:
函数(){
无功_that =这;
初始化日期
This.setYears({开始的:这。startyear,':这。endYear });
this.setmonths({开始的:这。startmonth });
this.setdays({ 'year:这个startyear,'month:这个startmonth,开始':这。个startDay });
/ /选择
this.eyear.onchange =函数(){
VaR年= parseInt(的价值);
开关(true){
案例(年= = _that。startyear){:
_that.setmonths({开始的:_that。startmonth });
_that.setdays({ 'year:_that。startyear,'month:_that。startmonth,开始:_that。岁寿辰});
破;
案例(年= = _that。endYear){:
_that.setmonths({开始:1,:_that。本月底});
如果(_that。本月底> 1){
_that.setdays({ 'year:_that。endYear,'month:1、开始:1 });
其他{ }
_that.setdays({ 'year:_that。endYear,'month:1、开始:1,:_that。endday });
}
破;
默认值:{
_that.setmonths({ 1 }开始的:);
_that.setdays({开始的:1、'year:今年,'month:1 });
}
}
}
选择月份
this.emonth.onchange =函数(){
VaR年= parseInt(_that。咿呀。
选项{ _that。咿呀。SelectedIndex }。值),
月= parseInt(的价值);
开关(true){
案例(年= = _that。endyearmonth = = _that。本月底):{
_that.setdays({开始的:1、'year:年,月,'month:':_that。endday });
破;
案例(年= = _that。startyearmonth = = _that。startmonth):{
_that.setdays({ 'year:_that。startyear,'month:_that。startmonth,开始:_that。岁寿辰});
破;
默认值:{
_that.setdays({开始的:1、'year:今年,'month:月});
}
}
}
},
设定年、月、日
----------------------------------
参数值
都是数字类型。
* /
{开始的的参数:XX,最终 / XXX }
setyears:功能(选配){
this.eyear.innerhtml =;
对于(var n = opt.start;n≤opt.end;n + +){
this.eyear.add(新的选项(n,n));
}
},
{开始的的参数:XX,最终 / XXX }
结束/忽略参数是可选的,从十二月开始。
setmonths:功能(选配){
this.emonth.innerhtml =;
VaR月= opt.end | | 12;
对于(var n = opt.start;n≤个月;n + +){
如果(n<10)n=0+ N;
this.emonth.add(新的选项(n,n));
}
},
{开始的:XX,'year ' / /参数:XXX,'month:XX,XX,'star:':XXX }
结束/忽略参数是可选的,开始到月底(判断月)。
setdays:功能(选配){
this.eday.innerhtml =;
VaR天= opt.end | | this.getdays(opt.year,选择。月);
对于(var n = opt.start;n<=天;n + +){
如果(n<10)n=0+ N;
this.eday.add(新的选项(n,n));
}
},
*根据年、月、返回的天数,如2016-2,返回是29天(闰年)
--------------------------------------------------------------
参数值都是数字类型。
* /
getdays:功能(年、月){
一天= { 31,28 | 29,31,30,31,30,31,31,30,31,30,31 } /无功;
二月/日数据处理数
无功feddays =年% 4 = = 029:28,
回天=;
VaR月=月< 10month = 0+月:month.tostring();
开关(月){
01案例:
2003案例:
05'case:
新加坡的情况:
08的案例:
例10':
例12:回天= 31;突破;
发行的情况:
国际的情况:
年的情况:
例11:回天= 30;突破;
例102:回天= feddays;打破;
}
返回天;
},
工具辅助功能
----------------------------------
* /
GetId:功能(ID){
返回document.getelementbyid(ID);
}
}
效果
显示:
效果不错,朋友自己美化,用自己的项目去。