选择一个元素,它的背景颜色在jQuery中不起作用

abi*_* er 5 javascript jquery

请检查我的代码.检查背景颜色的条件不起作用.

https://jsfiddle.net/oL7tdL22/1/

$(function(){

$(".testing").each(function(){
   if($(this).css("background-color")=="rgb(255,193,0)"){
     alert("found");
   }
   else{
     alert("not found");
   }
  });

});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="parent">
<div class="testing"  style="background-color:rgb(255,193,0)">
Test
</div>
</div>

<div class="parent">
<div class="testing"  style="background-color:rgb(220, 4, 81)">
Test
</div>
</div>


<div class="parent">
<div class="testing"  style="background-color:rgb(0, 186, 76)">
Test
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

当我们是警报背景颜色时,它正在工作.但我们无法匹配颜色.

Dij*_*Dij 5

你需要在rgb颜色代码中的每个逗号之后给出一个空格rgb(255, 193, 0).然后它工作.

$(function(){

$(".testing").each(function(){
   if($(this).css("background-color")=="rgb(255, 193, 0)"){
     alert("found");
   }
   else{
     alert("not found");
   }
  });

});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="parent">
<div class="testing"  style="background-color:rgb(255,193,0)">
Test
</div>
</div>

<div class="parent">
<div class="testing"  style="background-color:rgb(220, 4, 81)">
Test
</div>
</div>


<div class="parent">
<div class="testing"  style="background-color:rgb(0, 186, 76)">
Test
</div>
</div>
Run Code Online (Sandbox Code Playgroud)