简体   繁体   English

如果数组包含innerHTML,则更改单元格背景颜色

[英]Change cells background colour if array contains innerHTML

I'm trying to change those cells background colour that innerHTML values match with my array. 我正在尝试更改innerHTML值与我的数组匹配的那些单元格背景颜色。 How can i make it? 我该怎么做?

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";
    };

Are you sure this element select is correct: document.querySelector("[name='main']").contentWindow.document.getElementById("music").rows[i].cells[1] ? 你确定这个元素选择是正确的:document.querySelector(“[name ='main']”)。contentWindow.document.getElementById(“music”)。rows [i] .cells [1]? It hard analize without looking to html. 它很难分析,而不是寻找HTML。 If it OK, maybe you need such solution: 如果没问题,也许您需要这样的解决方案:

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";
    };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM