如何使用Struts2 + Jquery验证开始日期和结束日期,其中结束日期应大于开始日期。我有以下代码段
<div class="fb_pbdate">
<label>Start Date<span>*</span></label><span>
<sj:datepicker name="date" id="startdate" value="%{new java.util.Date()}"
displayFormat="dd/mm/yy" timepicker="true" timepickerShowSecond="false"
timepickerSecondText="false" timepickerFormat="hh:mm"
minDate="0" readonly="true" />
<span id="start_ht1" class="fb-error"></span></span>
</div>
<div class="fb_pbdate">
<label>Due Date<span>*</span></label><span>
<sj:datepicker name="enddate" id="enddate" value="%{new java.util.Date()}"
displayFormat="dd/mm/yy" timepicker="true" timepickerShowSecond="false"
timepickerSecondText="false" timepickerFormat="hh:mm"
minDate="0" readonly="true" />
<span id="enddate_ht2" class="fb-error"></span></span>
</div>
答案 0 :(得分:0)
1)用 Moment.js
做所有事情2)见Compare two dates in JavaScript它会 对你有帮助,
3)你可以通过date.js插件帮助
尝试使用DateJS,这是一个可以处理几乎所有内容的开源JavaScript日期库!以下示例正在运行:
<script type="text/javascript" src="date.js"></script>
<script>
startdate = "2009-11-01";
enddate = "2009-11-04";
var d1 = Date.parse(startdate);
var d2 = Date.parse(enddate) ;
if (d1 < d2) {
alert ("Error!");
}
</script>