js获取字体颜色

JavaScript08

js获取字体颜色,第1张

console.log(getComputedStyle(ttitle[i]).color)

if (getComputedStyle(ttitle[i]).color=="rgb(0, 0, 0)") {

ttitle[i].style.color ='#10adff'

}else{

ttitle[i].style.color ='#000'

}

需要个字体设置颜色让rgb=000

.ttitle{

text-align: left

color: #000

}

收集一个函数:获取随机颜色值

复制代码

代码如下:

function

getRandomColor(){

return

"#"+("00000"+((Math.random()*16777215+0.5)>>0).toString(16)).slice(-6)

}

说明:

1、16777215为16进制的颜色ffffff转成10进制的数字

2、>>数字取整

3、转成16进制不足6位的以0来补充

在线演示代码:

js随机颜色

document.writeln('#'+('00000'+(Math.random()*0x1000000