Javascript 如何将一周中的每一天动态绑定到HTML中的每一个h1

Javascript 如何将一周中的每一天动态绑定到HTML中的每一个h1,javascript,html,Javascript,Html,您好,您知道如何将一周中的每一天绑定到每个h1吗?第一个h1今天显示,下一个h1明天显示,第七个h1今天显示第七天?我做到了我最大的努力是我只能让他们今天都表现出来。。谢谢 函数currentdaychange(){ 让平日=[“星期日”, “星期一”, "星期二",, “星期三”, "星期四",, “星期五”, “星期六” ] [新日期().getDay()]; console.log(工作日) 让items=document.querySelectorAll('.currentday');

您好,您知道如何将一周中的每一天绑定到每个h1吗?第一个h1今天显示,下一个h1明天显示,第七个h1今天显示第七天?我做到了我最大的努力是我只能让他们今天都表现出来。。谢谢

函数currentdaychange(){
让平日=[“星期日”,
“星期一”,
"星期二",,
“星期三”,
"星期四",,
“星期五”,
“星期六”
]
[新日期().getDay()];
console.log(工作日)
让items=document.querySelectorAll('.currentday');
document.querySelector('.currentday')。innerHTML=工作日;
对于(变量i=0;i

您可以使用
Date.prototype.toLocaleDateString
并传入选项
{weekday:'long'}
检索一周中的本地化日期

const formatDayOfWeek=date=>
date.toLocaleDateString('en-US',{weekday:'long'});
const incrementDay=日期=>{
date.setDate(date.getDate()+1);
返回日期;
};
const currentDayChange=()=>{
const now=新日期();
[…document.querySelectorAll('.day of week')].forEach(day=>{
day.textContent=formatDayOfWeek(现在);
递增日(现在);
});
}
currentDayChange()
h1{
字体大小:较小;
}

类名不能包含
,更不用说以
开头了。另外,您得到的错误清楚地指向
“消息”:“TypeError:document.querySelector(…)为null”