“bootstrap 兼容日历”不在周一开始

我正在尝试让这段代码为我工作:

https://codepen.io/bbarry/pen/Eopdk

我希望日历从星期一开始。我已经将 .js 中的 days:[] 从 Sa-So 更改为 Mo-Su。

但这仅更改标题。日期还是错了,12月1日仍然是星期三,但今年应该是星期二。

我很确定问题出在 .html 中这部分附近的某个地方:

<thead>

  <tr class="c-weeks">

    {{ for (i = 0; i < 7; i++) { }}

      <th class="c-name">

        {{: days[i] }}

      </th>

    {{ } }}

  </tr>

</thead>

<tbody>

  {{ for (j = 0; j < 6 && (j < 1 || mode === 'month'); j++) { }}

  <tr>

    {{ for (i = 0; i < 7; i++) { }}

    {{ if (thedate > last) { dayclass = nextmonthcss; } else if (thedate >= first) { dayclass = thismonthcss; } }}

    <td class="calendar-day {{: dayclass }} {{: thedate.toDateCssClass() }} {{: date.toDateCssClass() === thedate.toDateCssClass() ? 'selected':'' }} {{: daycss[i] }} js-cal-option" data-date="{{: thedate.toISOString() }}">

      <div class="date">{{: thedate.getDate() }}</div>

      {{ thedate.setDate(thedate.getDate() + 1);}}

    </td>

    {{ } }}

  </tr>

  {{ } }}

</tbody>

我已经尝试更改循环(i = 0; i < 7; i++)但无法修复它。


慕勒3428872
浏览 68回答 1
1回答

qq_花开花谢_0

html 文件中的循环for (i = 0; i < 7; i++)仅打印 7 个标题单元格,迭代数组days并打印单元格中的数组值。正如您所看到的,这不会影响日期。您需要处理日期对象。html 文件中有 2 个日期对象:一个用于月视图,另一个用于周视图和日视图。月视图Date 对象在 html 文件的第 12 行实例化:first = new Date(year, month, 1),这意味着新的日期对象,传递参数年(上面为当前年份)和月份(上面定义为当前年份)。第三个参数是被视为该月第一天的月份中的某一天。将该参数设置为0。first = new Date(year, month, 0),周视图Date 对象在 html 文件的第 20 行实例化:thedate = new Date(date);日期设置在第 21 行:thedate.setDate(date.getDate() - date.getDay());只需设置日期如下:thedate.setDate(date.getDate() - date.getDay()+1);日视图:无需更改,因为您使用周视图的相同对象。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript