如何更改表格中点击单元格的单元格背景颜色? [英] How to change cell background color on click cell in table?
本文介绍了如何更改表格中点击单元格的单元格背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要更改lick上的单元格的颜色(只有两种颜色:黑色和白色),然后分析单元格的颜色以形成具有以下值的数组:1-黑色,0-白色?>
I need to change the color of the cells on сlick (only 2 colors: black and white), and then analyze the colors of cells to form an array with values: 1 - black, 0 - white?
推荐答案
尝试使用此代码切换颜色
Try this code to toggle the color
onClick="this.style.backgroundColor=='black' ? this.style.backgroundColor='white' : this.style.backgroundColor='black';"
然后您可以使用此功能获得颜色
And you get the Colors using this function
var tds = document.getElementsByTagName("td");
for(var i=0; i<tds.length; i++)
{
alert(tds[i].style.backgroundColor);
}
}
这篇关于如何更改表格中点击单元格的单元格背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文