Javascript:Daterange min 1 year

时间:2017-04-13 08:03:18

标签: javascript php html bootstrap-datepicker

我想将datedicker的日期范围'fromdate'设置为'afterdate'至少1年。我使用bootstrap作为datepicker并已经设置输入类型id'fromdate'和'afterdate'在javascript函数中调用。

这是我设法做到的:

<div class="input-append success date">
  <input type="text" class="form-control" value="<?= $_POST['fromdate'] ?>" name="fromdate" id="fromdate" style="width:185px;">
  <span class="add-on"><span class="arrow"></span><i class="fa fa-th"></i></span>
</div> 

<div class="input-append success date">
  <input type="text" class="form-control" value="<?= $_POST['nextdate'] ?>" name="nextdate" id="nextdate" style="width:185px;">
  <span class="add-on"><span class="arrow"></span><i class="fa fa-th"></i></span>
</div> 


<script>
    function validateReportRangeForm(){
      var x = document.forms["daterange"]["fromdate"].value.trim();
      var y = document.forms["daterange"]["nextdate"].value.trim();

      var x = x.split("-").reverse().join("/");
      var y = y.split("-").reverse().join("/");
      if ((Date.parse(x) > Date.parse(y))) {
        alert("'From Date' should be greater than 'To Next Days'");
        document.forms["daterange"]["nextdate"].focus();
        return false;
      }
}
</script>

enter image description here

  

输出:

enter image description here

0 个答案:

没有答案