本文地址:http://blog.csdn.net/stalendp/article/details/8102326
在开发android应用的时候,经常接触到颜色,由于eclipse中没有颜色识别的插件,所以写了一个html的简单的颜色识别器。
效果如下:
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Color Detector</title>
<script type="text/javascript">
function calc() {
var color = document.getElementById("color").value;
if(color.length!=7 && color.length!=9) {
alert(color.length + "The format of color is not correct!\r\n example: #010203 or #AA010203");
return;
}
var opacity = 1;
if(color.length==9) {
opacity = "0x" + color.substring(1, 3);
opacity = parseInt(opacity)/255;
color = '#' + color.substring(3, color.length);
}
var boxstyle = document.getElementById('box').style;
boxstyle.background=color;
boxstyle.opacity =opacity;
}
</script>
</head>
<body>
<div id="box" style="width: 150px; height: 50px; background: #e6e6e6; opacity:1"></div>
<input type="text" id="color" name="color" value="#e6e6e6" /> <input type="button" value="Ok" οnclick="javascript: calc();"/>
</body>
</html>
保存为html就可以使用了