如何检查CSS背景颜色是否为白色

How to check if the CSS background-color is white?

本文关键字:颜色 背景 是否 白色 CSS 何检查 检查      更新时间:2023-09-26

我需要这个:

$('*').each(function() {
        if($(this).css("background-color") == "#ffffff") {
           $(this).css("background-color") == "#000000"
        }
    });​​​​

完成一节课。

即使它是正确的(事实并非如此),它也不可靠,不太可能工作。原因是有几种显示白色的方法:

  • white
  • CCD_ 2及其所有64种情况的组合
  • CCD_ 3及其所有8种情况组合
  • CCD_ 4和all∞值之间任意空白的组合
  • CCD_ 5和all∞值之间任意空白的组合

你可以这样检查:

if( $(this).css("background-color").match(/^(?:white|#fff(?:fff)?|rgba?'('s*255's*,'s*255's*,'s*255's*(?:,'s*1's*)?'))$/i))
    this.style.backgroundColor = "#000";