HTML代码
<input name="" id="planRunDt" class="easyui-datebox" data-options="editable:false">
JS代码:
$('#planRunDt').datebox('setValue', getCurentDateStr()); //赋默认值为当前日期
$('#planRunDt').datebox('calendar').calendar({ //设置日期小于当前日期
validator : function(date){
var now = new Date();
var d1 = new Date(now.getFullYear(),now.getMonth(),now.getDate());
return date <= d1;
}
});
$('#start').datebox({//当选择开始日期时,给结束日期增加验证大于开始日期
onSelect: function(date){
$('#end').datebox('calendar').calendar({
validator : function(date1){
var d1 = new Date(date.getFullYear(),date.getMonth(),date.getDate());
return date1 >= d1;
}
});
}
});
function getCurentDateStr() {
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var clock = year + "-";
if(month < 10) clock += "0";
clock += month + "-";
if(day < 10) clock += "0";
clock += day;
return clock;
}
EasyUI DateBox 自定义验证
本文介绍如何使用 EasyUI 的 DateBox 组件,并通过 JavaScript 实现日期选择限制。包括设置默认日期为当前日期、限制选择日期不超过当天及确保起止日期范围的有效性。

被折叠的 条评论
为什么被折叠?



