你可以使用:
var s = "#ff0000";
var patt = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
var matches = patt.exec(s);
var rgb = "rgb("+parseInt(matches[1], 16)+","+parseInt(matches[2], 16)+","+parseInt(matches[3], 16)+");";
alert(rgb);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6479 次 |
| 最近记录: |