前面用到了jeDate日期控件的使用,https://cloud.tencent.com/developer/article/1411281,在这个控件的基础上,做出一些完善:关于jeDate日期控件的验证的问题:
一般会有三种情况:
1:对开始时间的验证,开始时间不能超过当前日期:
2:对结束时间的验证,结束时间不能超过当前日期:
3:开始时间和结束时间的区间验证
// 验证年月
function validate(numb) {
if ($("#beginDate").val() == '') {
layer.alert('开始日期不可为空', {
icon : 3
});
return true;
}
if (diffDate($("#beginDate").val()) == 0) {
layer.alert('开始日期不能超过当前日期', {
icon : 3
});
return true;
}
if ($("#endDate").val() == '') {
layer.alert('结束日期不可为空', {
icon : 3
});
return true;
}
if (diffDate($("#endDate").val()) == 0) {
layer.alert('结束日期不能超过当前日期', {
icon : 3
});
return true;
}
if (validateDate($("#beginDate").val(), $("#endDate").val())) {
layer.alert('结束日期不得小于开始日期', {
icon : 3
});
return true;
}
return false;
}
// 验证选中日期是否超过今天
function diffDate(evalue) {
var date=new Date(Date.parse(evalue.replace(/-/g,"/")));
if (new Date() > date) {
return 1;
}
return 0;
}
// 验证结束日期大于开始日期
function validateDate(beginTime, endTime) {
var bd = new Date(Date.parse(beginTime));
var ed = new Date(Date.parse(endTime));
return bd > ed;
}----
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有