easyui在选择日期的时候需要限制日期范围,比如选择日期的时候只能选今年1月1日到当天的时间范围,超过范围将无法选中,日期控件该怎么实现?
一、下面是从当天算起向前几天或向后几天可以选,其他时间不能选。
/** * 限制日期天数选择范围 * 参数:fieldName 字段名 * 参数:dayNum 可选天数范围,为正数表示向后dayNum天内可选,为负数表示向前dayNum天内可选,默认当天可选。 */function restrictDayRange(fieldName,dayNum){
$(function(){
$('#'+fieldName).datebox().datebox('calendar').calendar({
validator: function(date){
let _nowDate = new Date(); let arrayFullDate = dateChange(dayNum).split('-'); let d1 = new Date(_nowDate.getFullYear(), _nowDate.getMonth(), _nowDate.getDate()); let d2 = new Date(parseInt(arrayFullDate[0]), parseInt(arrayFullDate[1])-1, parseInt(arrayFullDate[2])); let flag = d1<=date && date<&