javascript - 为什么我不能将数组与类列表一起使用?
问题描述
我是 javascripts 的新手,所以我需要知道为什么我不能使用类似的代码
arr[0].classList.remove("whitecolor");
例如:
元素
const light_text_bed = document.getElementById("light_text_bed");
const light_icon_bed = document.getElementById("light_icon_bed");
const light_text_living = document.getElementById("light_text_living");
const light_icon_living = document.getElementById("light_icon_living");
数组
const Textdata = [light_text_bed,light_text_living];
const Icondata = [light_icon_bed,light_icon_living];
const Firedata = ["bedroomLight","livingAreaLight"];
手术
var count;
for (count = 0; count < Textdata.length; count++) {
const dbRef = firebase.database().ref().child(Firedata[count]);
dbRef.on("value", (snap) => {
var status = JSON.stringify(snap.val());
if (status == 1) {
Textdata[count].innerHTML = "On";
Textdata[0].classList.add("text-warning");
Icondata[0].classList.add("warning");
} else if (status == 0) {
Textdata[count].innerHTML = "Off";
Textdata[count].classList.add("whitecolor");
Icondata[count].classList.add("whitecolor");
}
});
}
解决方案
推荐阅读
- javascript - 如何在 javascript 中到达嵌套对象内部?
- bash - 在特定符号之间过滤具有匹配 ID 字符串的多 fasta 文件
- algorithm - 确定是否可以将一组节点视为有向无环图的孤立子图
- c# - VSTO Excel 插件仅适用于一个用户帐户(开发它的用户)
- wordpress - 如何为仅端口 8080 正确配置 Traefik Dashboard?
- r - dplyr 的 rowwise + replace_NAs:用其他列的值替换多列中的 NA
- python - 初学者 Python 和 API - 如何读取数据?
- java - Minecraft Block Harvest 等级限制
- javascript - Javascript报价幻灯片
- python - python selenium instagrambot - for i in range 循环(if 语句)