1

之前有人问过一个非常相似的问题,我对此很陌生,但我没有注意到以下代码和平中的错误。如果有什么问题,你能告诉我吗?

if ( $("#test").css("background-color") == "green" )

非常感谢!

4

2 回答 2

1

jquery api says:

...Different browsers may return CSS color values that are logically but not textually equal, e.g., #FFF, #ffffff, and rgb(255,255,255)....

So you should maybe try something like this

if($("#test").css('background-color') == 'rgb(0, 128, 0)' || $("#test").css('background-color') == '#00800') {...
于 2013-06-19T11:37:23.827 回答
-1
Try this:

$("#test").css( "background-color", "green" );
于 2013-06-19T11:36:01.170 回答