通过jQuery获取RGB背景颜色 [英] getting rgba background color by jquery

查看:661
本文介绍了通过jQuery获取RGB背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个background-color:rgba(1,0,0,0)元素,我需要通过jquery获取此值以执行某些操作.我尝试了$('.overlay').css("backgroundColor"),但它返回了transparent.有什么办法可以通过jquery获取元素的rgba背景色?

I have an element with background-color:rgba(1,0,0,0) and I need to get this value by jquery to do something. I tried $('.overlay').css("backgroundColor") but it returnstransparent. is there any way to get the rgba background-color of an element by jquery ?

顺便说一下,这是我的代码:

by the way, here are my codes :

html:

<div class="overlay"></div>

css:

.overlay { background-color:rgba(1,0,0,0) }

jquery:

$('.overlay').css("backgroundColor");

推荐答案

正如@coding仍指出的那样,Firefox返回transparent.但您仍然可以:

As @codingstill points out, Firefox returns transparent. But you could still do:

var bgColor = $('.overlay').css("backgroundColor");    
if(bgColor == 'transparent' || bgColor == 'rgba(1, 0, 0, 0)'){
    //do stuff
}

这篇关于通过jQuery获取RGB背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆