本文教大家如何实现laydate根据开始时间或者结束时间限制范围,供大家参考,具体内容如下
$(window).load(function(){//初始化时间控件
var cartimeDate = laydate.render({
elem: '#cartime' //用车时间
,type: 'datetime'
,format: 'yyyy-MM-dd HH:mm'
,done:function(value, date){
returntimeDate.config.min=getDateArray(date);//重点
}
});
var returntimeDate = laydate.render({
elem: '#returntime' //预计回车时间
,type: 'datetime'
,format: 'yyyy-MM-dd HH:mm'
,done:function(value, date){
cartimeDate.config.max=getDateArray(date);//重点
}
});
function getDateArray(date){//获取时间数组
var darray={};
darray.year=date.year;
darray.month=date.month - 1;
var day=date.date;
if(date.hours == 23 && date.minutes == 59 && date.seconds == 59){
day = day + 1;
}else{
darray.hours = date.hours;
darray.minutes = date.minutes;
darray.seconds = date.seconds;
}
darray.date=day;
return darray;
}
});