var btn = document.getElementById("btn");
var liObj = document.getElementById("list").getElementsByTagName("li");
console.log(liObj);
btn.onclick = function () {
//第一种
for (var i = 0; i < liObj.length; i += 2) {
console.log(liObj[i]);
/* if (i % 2 == 0) {
liObj[i].style.color = "red";
} */
liObj[i].style.color = "red";
}
//第二种
for (var i = 0; i < liObj.length; i++) {
console.log(liObj[i]);
if (i % 2 == 0) {
liObj[i].style.color = "red";
}
}
}
05-16
156
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交