javascript - 如果数组包含innerHTML,则更改单元格背景颜色
问题描述
我正在尝试更改那些 innerHTML 值与我的数组匹配的单元格背景颜色。我怎样才能做到?
var numbers = ["15628","15623","15656","11628"];
var table = document.querySelector("[name='main']")
.contentWindow.document.getElementById("music").rows.length;
for (i = 4; i < table -1; i++){
if (document.querySelector("[name='main']")
.contentWindow.document.getElementById("music").rows[i].cells[1].innerHTML == numbers)
{
document.querySelector("[name='main']")
.contentWindow.document.getElementById("music")
.rows[i].cells[1].style.backgroundColor = "yellow";
};
解决方案
你确定这个元素选择是正确的: document.querySelector("[name='main']").contentWindow.document.getElementById("music").rows[i].cells[1] ?不看 html 就很难分析。如果没问题,也许你需要这样的解决方案:
for (i = 4; i < table -1; i++){
let value = document.querySelector("[name='main']")
.contentWindow.document.getElementById("music").rows[i].cells[1].innerHTML;
if (numbers.includes(value))
{
document.querySelector("[name='main']")
.contentWindow.document.getElementById("music")
.rows[i].cells[1].style.backgroundColor = "yellow";
};
推荐阅读
- javascript - fullpage.js 向下箭头的问题
- python - Python Flask 请求表单:如何访问 select 元素的 option 子元素的 val 属性
- android - 如何在 android 的自定义对话框中设置自定义侦听器?
- javascript - 使用 Typescript 和 Webpack 管理依赖项的 AngularJS
- java - 将 Long 文件扫描成 java map
- sql - SQL:按变量等级检索数据
- vue.js - Vue 无法读取未定义的属性
- laravel - Laravel 5.3 日志权限 - 以无人身份创建/写入:nogroup
- android - 意图失败并在 SpeechFactory.fromSubscription 上取消(LUIS azure,android sdk)
- xgboost - Python、XGBoost、自定义目标函数:预测在迭代过程中保持不变,即使梯度不为零