用户选择一个颜色,获取反转的颜色
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1 "><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><title>颜色反转</title><style>div{width:200px;height:80px;background-color:#000;color:#fff;font-size:20px;text-align:center;line-height:80px;}</style><script>function hexToReverse(h) {var r = 0, g = 0, b = 0;r = 255 - parseInt(h[0],16)*16 - parseInt(h[1],16);g = 255 - parseInt(h[2],16)*16 - parseInt(h[3],16);b = 255 - parseInt(h[4],16)*16 - parseInt(h[5],16);return (r < 16 ? "0" + r.toString(16).toUpperCase() : r.toString(16).toUpperCase()) + (g < 16 ? "0" + g.toString(16).toUpperCase() : g.toString(16).toUpperCase()) + (b < 16 ? "0" + b.toString(16).toUpperCase() : b.toString(16).toUpperCase());}function getReverseColor(){var a = document.getElementById("choiceColor");var bg_str =a.value;var font_str = "#"+hexToReverse(bg_str.replace("#",""));var aa=document.getElementById("aa");aa.style.backgroundColor = bg_str;aa.style.color = font_str;//alert("背景颜色:"+bg_str);//alert("文字颜色:"+font_str);}</script></head><body>请选择主色(背景色)<input type="color" id="choiceColor"/><input type="button" value="反转" onclick="getReverseColor();"/><div id="aa">我是反转后的辅色</div></body></html>
