【问题标题】:How to increase days using javascript / jquery如何使用 javascript / jquery 增加天数
【发布时间】:2016-12-11 11:04:20
【问题描述】:

我有一个如下的工作日表。我需要展示整个星期。我能够打印当天、月份和工作日的名称,但我不知道如何打印增加 1 天的其余日期。如果您能提出一些建议,我将不胜感激。

     $(document).ready(function() {
        var d = new Date();
        var monthNames = ["JAN", "FEB", "NAR", "APR", "MAY", "JUNE", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
        var weekdays = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
        var currentmonth = monthNames[d.getMonth()];
        var weekday = weekdays[d.getDay()];
        var currentday = d.getDate();
        $('#currentday').text(currentday);
        $('#currentmonth').text(currentmonth);
        $('#weekday').text(weekday);
        });
    <div id="weekday">SUN</div>
    <div id="currentday ">11</div>
    <div id="currentmonth">DEC</div>
    <div>------------------------</div>
    <div id="">MON</div>
    <div id="">12</div>
    <div id="">DEC</div>

    <div id="">TUE</div>
    <div id="">13</div>
    <div id="">DEC</div>

    <div id="">WED</div>
    <div id="">14</div>
    <div id="">DEC</div>

    <div id="">THU</div>
    <div id="">15</div>
    <div id="">DEC</div>

    <div id="">FRI</div>
    <div id="">16</div>
    <div id="">DEC</div>

    <div id="">SAT</div>
    <div id="">17</div>
    <div id="">DEC</div>

【问题讨论】:

    标签: javascript jquery calendar days


    【解决方案1】:

    试试这个对你有帮助。 您需要获取当前日期时间,然后向其添加 1 天(1000*60*60*24)并对其进行迭代

    $(document).ready(function() {
      var d = new Date();
      var monthNames = ["JAN", "FEB", "NAR", "APR", "MAY", "JUNE", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
      var weekdays = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
    
      for (var i = 0; i < 7; i++) {
        var date = new Date(d.getTime() + ((1000 * 60 * 60 * 24) * i));
        var currentmonth = monthNames[date.getMonth()];
        var weekday = weekdays[date.getDay()];
        var currentday = date.getDate();
        var wkday = "weekday" + i;
        var currday = "currentday" + i;
        var currmnth = "currentmonth" + i;
        $('#body').append("<div id=" + wkday + "></div>");
        $('#body').append("<div id=" + currday + "></div>");
        $('#body').append("<div id=" + currmnth + "></div>");
        $('#' + currday).text(currentday);
        $('#' + currmnth).text(currentmonth);
        $('#' + wkday).text(weekday);
      }
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
    
    <body id="body">
    
    </body>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 2021-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      相关资源
      最近更新 更多