代码以下:
//日期输入框
$("input").datetimepicker({
format: 'yyyy-mm', //日期花样为“年-月”
startView:3, //最先的页面为月份挑选页面
minView: 3, //最小页面为月份挑选页面
autoclose: true,
language:'zh-CN'
});
$("input.dateStart").on("click",function(){
//将后一个输入框的日期值设为完毕日期
$(this).datetimepicker("setEndDate",$(this).next().val());
});
$("input.dateEnd").on("click",function(){
//将前一个输入框的日期值设为最先日期
$(this).datetimepicker("setStartDate",$(this).prev().val());
});
在运用中发明,在设置最先日期输入框中的日期后,点击完毕日期输入框时,显现的可选最先月份老是比开日期输入框中的月份晚两个月,比方,最先日期输入框中的日期为2016-01,那末完毕日期输入框中显现的可选最先月份就是三月。然则反过来,最先日期输入框中的可选完毕月份却没有题目。初步判断是在设置最先月份的语句上有题目。
看了一下源码,找到了缘由,是630行的代码应该是减1,而不是加1
startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
//****************bug代码行**********************//
//startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() + 1 : -Infinity,
//******************修改成**********************//
startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() - 1 : -Infinity,
endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() + 1 : Infinity,
修改后显现一般: