亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

How to display the current day of the week on a button?
P粉738676186
P粉738676186 2023-09-07 20:03:03
0
2
753

Is it possible to automatically display the day of the week on a button?

Please refer to the markup below, I need to make "Monday" display as the current day of the week.

<button class="button">征服星期一</button>

P粉738676186
P粉738676186

reply all(2)
P粉757556355

Can you use this js code to use Date().getDay() to return the day of the week between 0 and 6 and use the weekdays list to represent the day of the week?

//獲取具有id的按鈕
  const button = document.getElementById("dayButton");
  //星期幾的數(shù)組
  const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  //當(dāng)前星期幾的索引
  const currentDayiIndex = new Date().getDay();
  //點(diǎn)擊按鈕顯示星期幾
    dayButton.addEventListener("click",()=>{
        day.innerHTML = weekdays[currentDayiIndex]
        button.innerHTML = "征服" + weekdays[currentDayiIndex];
        })
<button class="button" id="dayButton">顯示星期幾</button>
<p id="day"></p>

hope this helps

P粉662614213

You can use Date::toLocaleDateString to display the current day of the week:

document.querySelector('.button').textContent = '征服 ' + new Date().toLocaleDateString('en-us', {weekday:'long'});
<button class="button"></button>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template