function rgb2hex(sRGB) {
// 判断是否符合格式
if (!/rgb\((\d{1,3}\,\s*){2}\d{1,3}\)/.test(sRGB)) {
return sRGB;
}
let colorTen = sRGB.substring(4, sRGB.length - 1).split(','); // 获取10进制值
let colorSixteen = '#';
colorTen.forEach(item => {
let num = parseInt(item.trim()).toString(16);
colorSixteen += num.length > 1 ? num : '0' + num;
})
return colorSixteen;
}