使用jQuery或JavaScript的三个持续时间或增量日期3持续时间

时间:2017-09-13 10:19:15

标签: javascript jquery

大家好,我是新手。

输入持续时间为3时,增加日期。

示例<input id"startdate" name"startdate"> = 1/1/2017

输出为: 2017年1月1日,2/1 / 2017,3 / 2017或1-1-2017,2-1-2017和3-1-2017

1 个答案:

答案 0 :(得分:1)

<!DOCTYPE html>
<html>
<body>
    <label>Enter Date:</label><input type="date" id="txtInput">
    <button type="button" onclick="getDates()">Submit</button>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
        crossorigin="anonymous"></script>
    <script src="https://d3js.org/d3.v4.min.js"></script>
    <script>
        function getDates() {
            var duration = 3;
            var selectDate = new Date($('#txtInput').val());
            var dateFormat = d3.timeFormat("%d-%m-%Y");
            var arrDates = [];
            var date = selectDate.getDate();
            for (var index = 0; index < duration; index++) {
               arrDates.push(dateFormat(new Date((new Date($('#txtInput').val())).setDate(date +(index)))));
            }
            alert(arrDates.join(','));
        }
    </script>
</body>
</html>