方便根据颜色代码查询颜色
<html>
<head>代码转颜色</head>
<script type="text/javascript">
function showcolor()
{
var colorcodeblock = document.getElementById("colorcode");
var colorcode = colorcodeblock.value;
var colorcodestr = "";
if(colorcode.indexOf("#")>=0)
colorcodestr = colorcode;
else
colorcodestr = "#" + colorcode;
var showblock = document.getElementById("showblock");
showblock.style.backgroundColor=colorcodestr;
}
</script>
<body>
输入颜色代码:
<input type="text" style="width:150px;height:40px;" id="colorcode" />
<input type="button" style="width:60px;height:30px;" value="显示" οnclick="showcolor()">
<div id="showblock" style="width:80px;height:60px;border:solid black;">
</div>
</body>
</html>
转载于:https://blog.51cto.com/guye1122/1434554