您的位置:首页 > Web前端 > JavaScript

如何js中判断页面上选择框中输入的两个日期的差值小于31

2017-10-31 10:02 489 查看
也许我这种办法比较笨,如果你有更好的办法,我希望能与我沟通。

先说一下需求:

页面上有两个选择时间的下拉框,如图



我需要完成的是账单结束时间和账单开始时间的差值在31天,因为数据太大,所以限制导出的数据量,然后我是这样实现的:

var start_time=$("#billcycle_start").val();
var end_time=$("#billcycle_end").val();
var a = new Array(3);
var b = new Array(3);
a=start_time.split('-');
b= end_time.split('-');

if(data_arr.length==0){
finedo.message.info("查询为空时不可导出");
return;
}else if(start_time==''||end_time==''){
finedo.message.info("请选择开始时间和结束时间");
}
else{
if(a[0]==b[0]){
if(a[1]==b[1]){
finedo.message.tip('正在导出请稍后...');
$("#downiframe").attr('src', '${ctx}/finedo/billsync/exportexcel' + (param ? '?' + $.param(param) : ''));
}else{
if(b[1]-a[1]==1){
if(b[2]<=a[2]){
finedo.message.tip('正在导出请稍后...');
$("#downiframe").attr('src', '${ctx}/finedo/billsync/exportexcel' + (param ? '?' + $.param(param) : ''));

}else{
finedo.message.info("请选择在一个月内的数据");
}
}else{
finedo.message.info("请选择在一个月内的数据");
}
}
}else{
finedo.message.info("请选择在一个月内的数据");
}
}先将年份进行比较,然后月份进行比较,如果月份相等,就直接导出,如果月份不相等,在对日进行比较,如果end_time的当前日小于start_time的当前日,也可以直接导出,否则是不可以的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: