/** *验证前后时间 **/ function _verificationTime(){ var a1 =$("#surveyDateStart").val(); var a2 =$("#surveyDateEnd").val(); if (a1.value != '' && a2.value != ''){ var d1 = a1.split(' '); var d2 = a2.split(' ') ; if(d1[0] == d2[0]){ var a = new Date(a1.replace(/-/g, '/')); var b = new Date(a2.replace(/-/g, '/')); if(b <= a){ return false; }else{ return true; } }else{ return false; } } }
实际例子
if(activityStateDate==null||activityStateDate==""){ alert("活动举办开始时间"); return ""; } if(activityEndDate==null||activityEndDate==""){ alert("活动举办结束时间"); return ""; } var d1 = activityStateDate.split(' '); var d2 = activityEndDate.split(' ') ; var a = new Date(activityStateDate.replace(/-/g, '/')); var b = new Date(activityEndDate.replace(/-/g, '/')); if(b <= a){ alert("结束时间必须大于开始时间"); return ""; }