function rgb2hex(sRGB) { // 匹配是否符合颜色格式 let erx = /rgb\((\d{0,3},\s*){2}\d{0,3}\)/ if(!erx.test(sRGB)) { return sRGB } // 找出xxx,xxx,xxx let reg = /(\d{0,3},\s*){2}\d{0,3}/ let matchArr = sRGB.match(reg)[0].split(',') let returnVal = '#' for(let item of matchArr) { item = ...