大家知道html顏色選擇嗎?下面我們就給大家詳細介紹一下吧!HTML顏色選擇器實現代碼需要的朋友可以參考下。
<p>HTML顏色選擇器</p>
<p>范圍:#000 - #FFF</p>
<style><!--
.divColor div
{
float:left;
width:5px;
height:5px;
line-height:0px;
font-size:0px;
cursor:pointer;
}
.divColor span
{
display:block;
float:left;
width:40px;
height:20px;
cursor:pointer;
}
.divColor .clear
{
height:auto;
width:auto;
clear:both;
font-size:0px;
line-height:0px;
}
--></style>
<p>
<input id="txtColor" style="border: solid 10px black; padding: 2px;" onmouseover="selectColor(this);" type="text" /></p>
<div class="divColor">
<script type="text/javascript">// <![CDATA[
function selectColor(o) {
o.style.backgroundColor = '#FFF';
o.style.border = 'solid 10px ' + (o.value == '' ? 'black' : o.value);
}
function showColor(color) {
document.getElementById('txtColor').style.border = 'solid 10px ' + color;
}
function setColor(color) {
var txtColor = document.getElementById('txtColor');
txtColor.value = color;
txtColor.style.backgroundColor = color;
txtColor.select();
txtColor.focus();
}
var c = '0123456789ABCDEF';
for (var r = 0; r < c.length; r++) {
var color = '#' + c.charAt(r) + c.charAt(r) + c.charAt(r);
document.write('<span onclick="setColor(\'' + color + '\');" onmouseover="showColor(\'' + color + '\');" style="background-color:' + color + ';"> </span>');
}
document.writeln('<div style="clear:both; height:5px;"></div>');
var begin = 0;
for (var i = 0; i < 2; i++) {
begin = i * 8;
for (var r = 0; r < c.length; r++) {
document.writeln('<div class="clear">');
for (var g = begin; g < begin + 8; g++) {
for (var b = 0; b < c.length; b++) {
var color = '#' + c.charAt(r) + c.charAt(g) + c.charAt(b);
document.write('<div onclick="setColor(\'' + color + '\');" onmouseover="showColor(\'' + color + '\');" style="background-color:' + color + ';"></div>');
}
}
document.writeln('</div>');
}
}
// ]]></script>
</div>
相信大家已經學會html顏色選擇了吧!感謝大家對我們網站的支持!
相關推薦:
html顏色名是什麼