亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

“bootstrap 兼容日歷”不在周一開始

“bootstrap 兼容日歷”不在周一開始

慕勒3428872 2023-12-14 15:41:11
我正在嘗試讓這段代碼為我工作: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++)但無法修復它。
查看完整描述

1 回答

?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊

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);

日視圖:無需更改,因為您使用周視圖的相同對象。

查看完整回答
反對 回復 2023-12-14
  • 1 回答
  • 0 關注
  • 173 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號