本文介绍了rgba的单独红色绿色蓝色值Colur值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将rgba
值设置为RGBA(205,31,31,1)
格式,我想将每个红色,绿色,蓝色和alpha值分开以进行进一步处理,如何使用jQuery实现它;所以输出看起来像
I'hv rgba
value in this format RGBA(205,31,31,1)
and I want to separate each red, green, blue and alpha value for further processing how can I achieve it using jQuery; so the output looks like
red = 205
green = 31
blue = 31
alpha =1
推荐答案
要从字符串变量中获取这些值很容易,可以使用以下答案,因此您不需要jQuery
To get these values from a string variable is easy with the following answer so you don't need jQuery
借助 正则表达式 ,您可以轻松实现它
With the help of regex, you can easily achieve it like
var color = "RGBA(205,31,31,1)";
var regExp = /\(([^)]+)\)/; // get the values within ()
var matches = regExp.exec(color);
var splits = matches[1].split(',');
alert("red: " + splits[0] + "green: " + splits[1]+ "blue: "+ splits[2]+ "alpha: " +splits[3] );
不过要从元素获取rgba
值,您可以使用jQuery的 css 方法.
However to get the rgba
value from an element you can use jQuery's css method.
这篇关于rgba的单独红色绿色蓝色值Colur值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!