歡迎大家在這裡學習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顏色名介紹