gpt4 book ai didi

javascript - HTMLCollection[] 未定义

转载 作者:行者123 更新时间:2023-12-03 01:05:54 24 4
gpt4 key购买 nike

rowGetter = i => {
const row = this.state.estimateItemList[i];
const selectRevison = this.state.selectedEstimate.revision;
const rowLenght = this.state.estimateItemList.length;
const changeColor = document.getElementsByClassName('rd') as
HTMLCollectionOf<HTMLElement>;
if (row.revision > selectRevison) {
for (let x = 0; x < changeColor.length; x++) {
row.changeColor.style.backgroundColor = 'red';
// changeColor.style.backgroundColor = 'red'; //this is get error(Cannot read property 'style' of undefined)
}
return row;
}
}

我想在条件 row.revision > this.state.selectedEstimate.revision 时更改行颜色。如何防止 this.color 发生变化。但是我没有收到任何错误,但行颜色没有改变,并且 changeColor : HTMLCollection [] 没有得到任何项目。它始终是未定义。我该如何解决这个问题?

最佳答案

你能试试这个吗:

const changeColor = document.getElementsByClassName('rd');

而不是:

const changeColor = document.getElementsByClassName('rd') as HTMLCollectionOf;

关于javascript - HTMLCollection[] 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52412493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com