我是初学者。当输入持续时间为3时设置增量日期。例如
<input id="startdate" name="startdate">
当前值为1/1/2017。输出需要:
1/1/2017 2/1/2017 3/1/2017
或
1-1-2017 2-1-2017 3-1-2017
vhipe2zx1#
<!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>
1条答案
按热度按时间vhipe2zx1#