How to convert color from (rrr ggg bbb) to RRGGBB by javascript

做~自己de王妃 提交于 2019-12-24 16:18:42

问题


I have this code (in Selenium IDE): storeEval | window.document.defaultView.getComputedStyle(window.document.getElementsByTagName('input')[0]).getPropertyValue('background-color') | result

it's returns me color in (rrr, ggg, bbb), how can i get this color in RRGGBB?


回答1:


Try this:

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



回答2:


you can convert the decimal value (0 - 255) to hex (0 - FF)

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


来源:https://stackoverflow.com/questions/10699039/how-to-convert-color-from-rrr-ggg-bbb-to-rrggbb-by-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!