2012-05-22 37 views
1

我有這樣的代碼(在硒IDE): storeEval | window.document.defaultView.getComputedStyle(window.document.getElementsByTagName('input')[0]).getPropertyValue('background-color') | result如何顏色從(RRR GGG BBB)通過轉換爲RRGGBB的JavaScript

它返回我的色彩在(rrr, ggg, bbb),我怎麼能得到這個顏色RRGGBB

+0

這裏是如何做到在Javascript轉換HTTP:/ /stackoverflow.com/q/57803/1399920 – n00begon

回答

3

試試這個:

command: storeEval 
target : color = window.document.defaultView.getComputedStyle(window.document.getElementsByTagName('input')[0]).getPropertyValue('background-color'); colorArr = color.replace(/[(rgb()\)]/g, '').split(','); hexString = parseInt(colorArr[0]).toString(16) + parseInt(colorArr[1]).toString(16) + parseInt(colorArr[2]).toString(16); 
value : result 
+0

「[信息]回聲:NaNe6ff;」必須#CCE6FF)) – user1211063

+0

但是,非常感謝你 – user1211063

+0

Большоеспасибозапомощь)чутьч утьнеправильныйreplaceионнемогконвертировать[0]массив。 ещёразспасибо – user1211063

1

可以十進制值(0 - 255)轉換爲十六進制(0 - FF)

var hexString = redNumber.toString(16) + greenNumber.toString(16) + blueNumber.toString(16); 
+0

對不起,但我不能undestand,我怎麼能用我的代碼在硒IDE( – user1211063