gpt4 book ai didi

javascript - 在 JavaScript 中比较单元格背景颜色

转载 作者:行者123 更新时间:2023-11-28 04:59:44 25 4
gpt4 key购买 nike

根据表格单元格的当前颜色,我尝试在鼠标离开单元格时更改颜色或保持不变。这是我的脚本:

<script>
$('.tableCell')
.mouseenter(function () {

$(this).find(".hideCheckBox").show();
})
.mouseleave(function () {

$(this).find(".hideCheckBox").hide();
if ($(this).find(".hideCheckBox").is(":checked")) {
$(this).css("backgroundColor", "#10657e");
$(this).css("color", "white");
}
else {
if ($(this).style.backgroundColor === "#157fa0") {

} else {
$(this).css("backgroundColor", "white");
$(this).css("color", "black");
}
}
});
</script>

但是我的比较(如下)不起作用。我如何在 JavaScript 中进行比较才能使其正常工作?

if ($(this).style.backgroundColor === "#157fa0") {

最佳答案

尝试比较 RGB 值:

if ($(this).style.backgroundColor == 'rgb(21, 127, 160)') {

关于javascript - 在 JavaScript 中比较单元格背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42229844/

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