function rgb2hex(sRGB) { <!-- 核心在于,利用正则表达式进行格式检查以及数字获取。--> <!-- 1、检查sRGB是否符合 rgb(数字, 数字, 数字) 的格式-> const rule=/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/i; const isMatch=sRGB.match(rule) <!-- 2、不符合格式,直接返回sRGB--> if(!isMatch){ return sRGB } <!-- 3、符合格式,获取rgb三个数值,判断是否在0~255之间--> const r...