gpt4 book ai didi

javascript - 单击时交换表格单元格颜色

转载 作者:太空宇宙 更新时间:2023-11-03 21:00:27 25 4
gpt4 key购买 nike

我希望能够单击一个表格单元格,将其切换为颜色 1,然后在下一次单击时将其切换为颜色 2,然后返回颜色 1...等等。

function cSwap(cell){ 
if (cell.style.backgroundColor = "#00000F")
{
cell.style.backgroundColor = "#F00000";
}
else if (cell.style.backgroundColor = "#F00000")
{
cell.style.backgroundColor = "#00000F";
}
}

现在,它只会更改为第一种颜色,随后的点击什么都不做。

表格的每个单元格如下所示:

<td classname='t' onclick='cSwap(this);' width='100' height='100' id='nw'><a href="" id="nw"></a></td>

...一旦我让一切正常工作,这将是 CSS(题外话)。

最佳答案

你需要双等号来比较:

  if (cell.style.backgroundColor == "#00000F")

triple如果您愿意,等于。

关于javascript - 单击时交换表格单元格颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4120444/

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