手机版

原生射流研究…实现日期联动

时间:2021-10-15 来源:互联网 编辑:宝哥软件园 浏览:

月份的判定,由于涉及到过多了判定条件,如果用如果不是这样会大大降低性能,建议用转换语法

代码如下:

复制代码代码如下:getDays:function(年、月){ //var aDay=[31,28|29,31,30,31,30,31,31,30,31,30,31,30,31,30,30,30,30,31];//二月份的天数数据处理var FedDays=年份%4==0?29:28,returnDays=var month=?month=' 0 ' month : month。ToString();switch(month){ case ' 01 ' : case ' 03 ' : case ' 05 ' : case ' 07 ' : case ' 08 ' : case ' 10 ' : case ' 12 ' :退货天数=31;打破;案例' 04 ' :案例' 06 ' :案例' 09 ' :案例' 11 ' :返回天数=30;打破;案例' 02 ' :返回天数=FedDays打破;}退货退货天数}

完整的源代码:

复制代码代码如下:/*作者:老挝顾雍-日期三级联动,范围选择-参数*[字符串]目标s : ' #年、#月、#日;年,月,日的id *[字符串]范围:'2013-02-03,2019-09-21 ';范围,正确格式为xxxx-xx-xx -为了节省代码,请传入正确的日期范围参数-错误示范:(1)范围:'2013-02-03,2019-9-21 '是不对的,注意日期格式(2)范围:'2013-02-03 '是不对的,请输入完整的范围之值(3)范围:'2013-02-03,2016-02-30 '是不对的,2月没有30天(3)范围:'2013-02-03,2011-02-30 '是不对的,范围错误了* */函数GySetDate(opt){//elem var targets=opt。目标。split(',');这个。eyear=这个。getid(目标[0]).切片(1));这个。emonth=这个。getid(目标[1]).切片(1));这个。EdAy=这个。Getid(目标[2]).切片(1));if(!this.eYear||!this.eMonth||!this.eDay)返回;//范围值var r=opt.range.indexOf(','),aStarts=opt.range.slice(0,r).拆分('-'),//转为:['2013 ',' 05 ',' 20'] aEnds=opt.range.slice(r 1,opt.range.length).拆分('-');//转为:['2018 ',' 08 ',' 20 ']//编号类型这个。startyear=parsent(aStarts[0],10);这个。开始月份=parsent(aStarts[1],10);这个。startday=parsent(aStarts[2],10);这个。年末=parsent(aEnds[0],10);这个。月末=parsent(aEnds[1],10);这个。endday=parsent(aEnds[2],10);

这个。init();} GySetDate。prototype={ init : function(){ var _ that=this;//初始化日期这个。setyears({ ' start ' : this。今年年初,年年底。end year });这个。setmonths({ ' start ' : this。开始月份});这个。setdays({ ' year ' : this。startyear,' month':this.startMonth,' start ' : this .start day });//年选择这个。艾亚尔。onchange=function(){ var year=ParSeint(this。值);switch(true){ case(year==_ that。开始年份): { _那。setmonths({ ' start ' : _ that。开始月份});_那个。setdays({ ' year ' : _ that。startyear,' month':_that.startMonth,' start ' : _ that .start day });};打破;案例(年份==_那。年终): { _那。setmonths({ ' start ' :1,' end ' : _ that。结束月份});如果(_那。结束月份1){ _即。setdays({ ' year ' : _ that。年末,'月' :1,'开始' :1 });} else { _ that。setdays({ ' year ' : _ that。年末,‘月’:1,‘开始’:1,‘结束’: _ that。end day });} };打破;默认值: { _ that。setmonths({“start”:1 });_that.setDays({'start':1,' year':year,' month ' :1 });} } } //月选择这个。艾蒙思。onchange=function(){ var year=parent(_ that。艾亚尔。选项[_即。艾亚尔。selectedindex].值),月=ParSeint(这个。值);switch(true){ case(year==_ that。年末月==_那个。月末): { _那。setdays({ ' start ' :1,' year':year,' month':month,' end ' : _ that。end day });};打破;案例(年份==_那。startyearmonth==_ that。startmonth): { _ that。setdays({ ' year ' : _ that。startyear,' month':_that.startMonth,' start ' : _ that .start day });};打破;默认值: { _ that。setdays({ ' start ' :1,' year':year,' month ' : month });} } } }, /*设置年,月,日-参数值都为数字类型*///参数{'start':xx,' end ' : xx } setyears :函数(opt){ this。艾亚尔。innerhtml=for(var n=opt。开始;n=opt.endn ){ this.eYear.add(新选项(n,n));} }, //参数{'start':xx,' end ' : xx }//参数结束为可选,忽略,则开始到12月setmonths :函数(opt){ this。艾蒙思。innerhtml=var months=opt . end | | 12 for(var n=opt。开始;n=月;n){ if(n10)n=' 0 ' n;this.eMonth.add(新选项(n,n));} }, //参数{'start':xx,' year ' :xxx,' month':xx,' star':xx,' end ' : xx }//参数结束为可选,忽略,则开始到本月底(根据月份判断的)setdays :函数(opt){ this。艾迪。innerhtml=var days=opt。end | |这个。getdays(opt。年份,选择。月);for(var n=opt。开始;n=天数;n){ if(n10)n=' 0 ' n;this.eDay.add(新选项(n,n));} }, /* 根据年,月,返回正确的天数,如2016-2,返回是29天(润年) - 参数值都为数字类型*/GetDays 3360 function(年、月){ //var aDay=[31,28|29,31,30,31,30,31,31,30,31,30,30,30,30,31,30,30,31,30,31];//二月份的天数数据处理var FedDays=年份%4==0?29:28,returnDays=var month=?month=' 0 ' month : month。ToString();switch(month){ case ' 01 ' : case ' 03 ' : case ' 05 ' : case ' 07 ' : case ' 08 ' : case ' 10 ' : case ' 12 ' :退货天数=31;打破;案例' 04 ' :案例' 06 ' :案例' 09 ' :案例' 11 ' :返回天数=30;打破;案例' 02 ' :返回天数=FedDays打破;returnDays },/*工具辅助函数-*/getid :函数(id){返回文档。getelementbyid(id);}}

效果展示图:

效果还不错吧,小伙伴们自己美化下,使用到自己的项目中去吧。

版权声明:原生射流研究…实现日期联动是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。