1
我無法想象一個邏輯來實現始終大於開始日期的結束日期。這是我的視圖代碼,並有兩個字段事件結束和事件開始。嘗試執行,如Validate that end date is greater than start date with jQuery所示,但失敗。如何實現這一點?比較日期 - 結束日期應該大於開始日期
<div class="clearfix"></div>
<div class="control-group form-group">
<label class="control-label col-md-4" style="text-align:left">Event Start</label>
<div class="controls" style="margin-left:0px">
<div class="col-md-3 date" data-date="12-02-2012" data-date-format="dd-mm-yyyy" data-date-viewmode="years">
<input class="m-wrap col-md-11 m-ctrl-medium datepicker form-control" required="required" name="starttimedate" id="ed_starttimedate" type="text" value="<?php echo $_POST['starttime']?date('d-m-Y',$_POST['starttime']):date('d-m-Y'); ?> " />
<!-- <span class="add-on"><i class="fa fa-calendar" style="margin-top:5px"></i></span> -->
</div>
<div class="col-md-1"> </div>
<div class="col-md-3 bootstrap-timepicker-component">
<input class="m-wrap col-md-11 m-ctrl-medium timepicker-default form-control" required="required" value="<?php echo date('h:i A',$_POST['starttime']);?>" name="starttimetime" id="ed_starttimetime" type="text" />
<!-- <span class="add-on"><i class="fa fa-clock-o" style="margin-top:5px"></i></span>-->
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="clearfix"></div>
<div class="control-group form-group">
<label class="control-label col-md-4" style="text-align:left">Event End</label>
<div class="controls ">
<div class="col-md-3 date" data-date="12-02-2012" data-date-format="dd-mm-yyyy" data-date-viewmode="years">
<input class="m-wrap col-md-11 m-ctrl-medium datepicker form-control" required="required" name="endtimedate" id="ed_endtimedate" type="text" value="<?php echo $_POST['endtime']?date('d-m-Y',$_POST['endtime']):date('d-m-Y'); ?> " />
<!--<span class="add-on"><i class="fa fa-calendar" style="margin-top:5px"></i></span>-->
</div>
<div class="col-md-1"> </div>
<div class="col-md-3 bootstrap-timepicker-component">
<input class="m-wrap col-md-11 m-ctrl-medium timepicker-default form-control" required="required" value="<?php echo date('h:i A',$_POST['endtime']);?>" name="endtimedatetime" id="ed_endtimedatetime" type="text" />
<!-- <span class="add-on"><i class="fa fa-clock-o" style="margin-top:5px"></i></span>-->
</div>
</div>
腳本是:
<script>
$("#ed_endtimedate").change(function() {
var startDate = document.getElementById("ed_starttimedate").value;
var endDate = document.getElementById("ed_endtimedate").value;
if ((Date.parse(ed_endtimedate) <= Date.parse(ed_starttimedate))) {
alert("End date should be greater than Start date");
document.getElementById("ed_endtimedate").value = "";
}
});
</script>
請不要放所有的代碼。創建一個**最小和可驗證的樣本**。 – Rajesh
_Codeigniter-2&Codeigniter-3_以防萬一我假設 – RiggsFolly
可能有10行代碼與此問題相關。請刪除噪音,只顯示我們的相關代碼 – RiggsFolly