第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我將如何修復(fù)此功能以根據(jù)日期更改月份?

我將如何修復(fù)此功能以根據(jù)日期更改月份?

子衿沉夜 2023-04-27 10:34:34
我正在嘗試創(chuàng)建一個(gè)函數(shù),該函數(shù)根據(jù)字符串中提供的日期創(chuàng)建動(dòng)態(tài)日期范圍。到目前為止我做了什么:在我要更改的字符串中捕獲日期;檢查該日期是否為星期四(如果是,則該范圍需要考慮周末)我需要做什么:找到一種方法來(lái)獲取范圍內(nèi)的第二個(gè)日期以考慮周末;想辦法確保第二個(gè)日期考慮到該月的最后一天。為舊語(yǔ)法道歉,GTM 不喜歡使用 ES6 的任何東西,所以我在這個(gè)項(xiàng)目上有點(diǎn)受限。注意我使用的是 DD/MM/YYYYvar regex = /[\d\/\d\/\d]/g;var text = dument.querySelector('.shipmentLineTitle b');var originalDate = text.innerText.match(regex, "");if (originalDate.length > 10) {    originalDate.pop();    originalDate.join('');}var ogDateString = originalDate.join('');var dayNumber = originalDate.splice(0, 2).join('');var monthNumber = originalDate.splice(1, 2).join('');var yearNumber = originalDate.splice(2, 4).join('');// if originalDate is a thursday (5) dynamicString will need to be a Monday (1).var date = new Date(yearNumber, monthNumber -1, dayNumber);var dynamicDateString = "";if (date.getDay == 5) {    var newDate = new Date(date) + (86400000 * 3);    var dd = newDate.getDate();    var mm = newDate.getMonth() +1;    var yy = newDate.getFullYear();    dymamicDateString = dd + '/' + mm + '/' + yy;} else {    var newDate = new Date(date) + 86400000;    var dd = newDate.getDate();    var mm = newDate.getMonth() +1;    var yy = newDate.getFullYear();    dynamicDateString = dd + '/' + mm + '/' + yy;}var newContent = 'Delivery will be made between ' + ogDateString + ' - ' + dynamicDateString + '. An accurate delivery date will be provided after you place your order.';text.innerText = newContent;<span class="shipmentLineTitle">Delivery details: <b>your delivery will arrive on 09/10/2020 (1 delivery)</b></span>
查看完整描述

2 回答

?
元芳怎么了

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個(gè)贊

星期四是第 4 天


這是一個(gè)更簡(jiǎn)單的腳本


var textField = document.querySelector('.shipmentLineTitle b'),

  text = textField.innerText,

  originalDate = text.match(/\d{2}\/\d{2}\/\d{4}/)[0].split("/"),

  dayNumber = +originalDate[0],

  monthNumber = +originalDate[1],

  yearNumber = +originalDate[2],

  date = new Date(yearNumber, monthNumber - 1, dayNumber, 15, 0, 0, 0),

  aDay = 86400000,

  newDate = new Date(date),

  day = date.getDay(),

  daysToAdd = 1; // Sunday to Wednesday


// if originalDate is a Thursday (4) or Saturday (6), dynamicString will need to be a Monday (1).


if (day === 4) daysToAdd = 4; // Thursday - delivery Monday

else if (day === 6) daysToAdd = 2; // Saturday


newDate.setDate(newDate.getDate() + daysToAdd);

var dd = newDate.getDate(),

  mm = newDate.getMonth() + 1,

  yy = newDate.getFullYear(),

  dynamicDateString = dd + '/' + mm + '/' + yy,

  newContent = text + ' - ' + dynamicDateString + '</b>. An accurate delivery date will be provided after you place your order.';

textField.innerHTML = newContent;

<span class="shipmentLineTitle">Delivery details: <b>your delivery will arrive on 08/10/2020 (1 delivery)</b></span>


查看完整回答
反對(duì) 回復(fù) 2023-04-27
?
慕姐4208626

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊

我建議用戶 moment.js 一個(gè)非常好的日期庫(kù)來(lái)操作日期。它有很多添加/減去日期、小時(shí)、天等的功能。



查看完整回答
反對(duì) 回復(fù) 2023-04-27
  • 2 回答
  • 0 關(guān)注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)