我们在使用EasyUI的datebox的时候,往往会限制选择的日期在一定范围内,因为EasyUI的daterbox在创建的时候,会包含一个calendar,所以可以通过一下代码限制选择的日期为今天以及3天后。
$('#performDate').datebox('calendar').calendar({
validator: function(date){
var now = new Date();
var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var d2 = new Date(now.getFullYear(), now.getMonth(), now.getDate()+3);
return d1<=date && date<=d2;
}
});
如果是限制出生日期的话,那么就限制输入日期不能大于今天。
$('#dd').datebox('calendar').calendar({
validator: function(date){
var now = new Date();
var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
return date<=d1;
}
});