第二部分1.3遍历dom
最后一个任务有意思。
书上看来以为自己会了是假的,做题实践用出来才是正途。
first last 快捷方式,要是批量处理还是用下表法通用。
体会到循环的诞生原因,就是因为重复的东西需要写好多遍。
不知道为啥,firefox会自动在html文档中的table下添加tbody,如果你没写的话。
/*
document.body.firstElementChild.firstElementChild.firstElementChild.firstElementChild.style.backgroundColor = "red";
document.body.firstElementChild.firstElementChild.children[1].children[1].style.background = "red";
document.body.firstElementChild.firstElementChild.children[2].children[2].style.background = "red";
document.body.firstElementChild.firstElementChild.children[3].children[3].style.background = "red";
document.body.firstElementChild.firstElementChild.children[4].children[4].style.background = "red";
*/
/*
first last 快捷方式,要是批量处理还是用下表法通用。
体会到循环的诞生原因,就是因为重复的东西需要写好多遍。
不知道为啥,firefox会自动在html文档中的table下添加tbody,如果你没写的话。
*/
/*
//while循环版本
let i = 0;
while (i < 5) {
document.body.children[0].children[0].children[i].children[i].style.background = "red";
i++;
}
*/
//for循环版本
for (let i = 0; i < 5; i++) {
document.body.children[0].children[0].children[i].children[i].style.background = "red";
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步