使用JavaScript验证日期(排放日期如何始终大于录取日期)

时间:2017-07-11 02:26:48

标签: javascript html css

我的html代码中有录取日期和出院日期。现在我可以验证日期,使得出院日期总是大于入院日期吗?如果有人愿意帮助我,我将非常感激。

以下是相同的html和JavaScript代码:

$(document).ready(function() {
  $("#txtFromDate").datepicker({
    numberOfMonths: 2,
    onSelect: function(selected) {
      $("#txtToDate").datepicker("option", "minDate", selected)
    }
  });
  $("#txtToDate").datepicker({
    numberOfMonths: 2,
    onSelect: function(selected) {
      $("#txtFromDate").datepicker("option", "maxDate", selected)
    }
  });
});

HTML:

Admission Date:<input type="date" name="admission_dt" id="txtFromDate" required/> 
Discharge Date:<input type="date" name="discharge_dt" id="txtToDate" required/>

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
const admissionDate = new Date('2016-01-01');
const dischargeDate = new Date('2017-01-01');

function isDischargeGreaterThanAdmission(admissionDate, dischargeDate){
	return dischargeDate > admissionDate;
}

console.log(isDischargeGreaterThanAdmission(admissionDate, dischargeDate));
&#13;
&#13;
&#13;