您的位置:首页 > Web前端 > JavaScript

【javascript】Convert any colour value to hex in MSIE

2012-07-12 14:07 393 查看
The following function will convert any colour value (rgb, named colours, etc) to the hex equivalent in MSIE:

function toHex(color) {

var body = createPopup().document.body,

range = body.createTextRange();

body.style.color = color;

var value = range.queryCommandValue("ForeColor");

value = ((value & 0x0000ff) << 16) | (value & 0x00ff00) | ((value & 0xff0000) >>> 16);

value = value.toString(16);

return "#000000".slice(0, 7 - value.length) + value;

};

For other browsers you can use
getComputedStyle()
so that is already a solved problem.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐