Home > Web Front-end > JS Tutorial > JavaScript date verification: the input date is greater than or equal to the current date_javascript skills

JavaScript date verification: the input date is greater than or equal to the current date_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:26:04
Original
2100 people have browsed it

This article analyzes the javascript input date greater than or equal to the current date verification code through an example, and shares it with everyone for your reference. The details are as follows:

<script>
  $(function () {
    var d = new Date();

    var strDate = getDateStr(d);
    $("#beginTime").val(strDate);
    $("#endTime").val(strDate);
    //$("#beginTime").val("2015-10-10");

    $("#beginTime").change(function () {
    var d2 = new Date($("#beginTime").val());
    if (d2 < d) {
      alert("填写的动工日期必须大于当前日期.");
      $("#beginTime").val(strDate);
    }
    });
    $("#endTime").change(function () {
    var d2 = new Date($("#beginTime").val());
    var d3 = new Date($("#endTime").val());
    if (d3< d2) {
      alert("填写的完工日期不能小于动工日期.");
      $("#endTime").val(getDateStr(d2));
    }
    });
  });

  function getDateStr(date) {
    var month = date.getMonth() + 1;
    var strDate = date.getFullYear() + '-' + month + '-' + date.getDate();
    return strDate;
  }
</script>

Copy after login

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template