var rgb = $(obj).css('background-color'); var r2 = /rgb((.+?),(.+?),(.+?))/; function hex(x) { return ("0" + parseInt(x).toString(16)).slice(-2); } var bc = hex(r2.exec(rgb)[1]) + hex(r2.exec(rgb)[2]) + hex(r2.exec(rgb)[3]);
rgb变为#xxx格式