Metode pemanggilan: colorSelect('ID kotak masukan nilai warna', 'ID Kontainer yang menampilkan nilai warna', peristiwa), sangat mudah untuk dipanggil, cukup onClick. Terima kasih kepada: Cabai Merah
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns=" http://www.w3.org/1999/xhtml ">
<kepala>
<meta http-equiv="Jenis Konten" content="teks/html; charset=utf-8" />
<title>Palet</title>
<gaya>
#colorBoard{posisi:absolute; padding:10px; lebar:256px; tinggi:220px; latar belakang:#f3f3f3;
#colorBank{ jelas:keduanya; batas:#d9d9d9 1px padat; latar belakang:#FFF; lebar:252px; padding:0 0 2px 2px;
#colorBank div{ luapan:tersembunyi; tinggi:12px; lebar:12px; margin:2px 2px 0 0;
#colorViews{width:80px; height:20px; float:left;border:#d9d9d9 1px solid; latar belakang:#000; tampilan:blok;
#colorInput{lebar:70px; tinggi:18px; float:kiri; font-family:Verdana; ukuran font:13px; warna:#333; tampilan:blok; padat;margin: 0 10px 10px 0;}
#colorClose{lebar:80px; warna:#999999; tinggi:22px; float:kiri;tampilan:blok; latar belakang:#f3f3f3;kursor:pointer;batas:#d9d9d9 batas atas:#FFF batas padat; -kiri:#FFF 1 piksel padat;}
</gaya>
<skrip>
fungsi colorSelect(sekarang,halaman,e){
if(document.getElementById("colorBoard")){
kembali;
}
//Tentang posisi penampilan
e=e||peristiwa;
var scrollpos = getScrollPos();
var l = gulirpos.l + e.klienX;
var t = scrollpos.t + e.clientY + 10;
jika (l > getBody().clientWidth-253){
l = getBody().clientWidth-253;
}
//Buat DOM
var nowColor = document.getElementById(sekarang);
var pageColorViews = document.getElementById(halaman);
var ColorHex=Array baru('00','33','66','99','CC','FF');
var SpColorHex=Array baru('FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF');
var colorBank = dokumen.createElement("div");
colorBank.setAttribute("id","colorBank");
var colorViews = dokumen.createElement("div");
colorViews.setAttribute("id","colorViews");
var colorInput = dokumen.createElement("input");
colorInput.setAttribute("id","colorInput");
colorInput.setAttribute("ketik","teks");
colorInput.setAttribute("dinonaktifkan","dinonaktifkan");
var colorClose = dokumen.createElement("input");
colorClose.setAttribute("id","colorClose");
colorClose.setAttribute("nilai","Batal");
colorClose.setAttribute("ketik","tombol");
colorClose.onclick=function(){document.body.removeChild(colorBoard)};
var colorBoard =document.createElement("div");
colorBoard.id="colorBoard";
colorBoard.style.kiri = l+"px";
colorBoard.style.top = t+ "px";
colorBoard.appendChild(colorViews);
colorBoard.appendChild(colorInput);
colorBoard.appendChild(colorClose);
colorBoard.appendChild(colorBank);
dokumen.body.appendChild(colorBoard);
//Keluarkan palet
untuk(b=0;b<6;b++){
untuk(a=0;a<3;a++){
untuk(i=0;i<6;i++){
colorItem = dokumen.createElement("div");
colorItem.style.backgroundColor="#"+ColorHex[a]+ColorHex[i]+ColorHex[b];
colorBank.appendChild(colorItem);
}
}
}
untuk(b=0;b<6;b++){
untuk(a=3;a<6;a++){
untuk(i=0;i<6;i++){
colorItem = dokumen.createElement("div");
colorItem.style.backgroundColor="#"+ColorHex[a]+ColorHex[i]+ColorHex[b];
colorBank.appendChild(colorItem);
}
}
}
untuk(i=0;i<6;i++){
colorItem = dokumen.createElement("div");
colorItem.style.backgroundColor="#"+ColorHex[0]+ColorHex[0]+ColorHex[0];
colorBank.appendChild(colorItem);
}
untuk(i=0;i<6;i++){
colorItem = dokumen.createElement("div");
colorItem.style.backgroundColor="#"+ColorHex[i]+ColorHex[i]+ColorHex[i];
colorBank.appendChild(colorItem);
}
untuk(i=0;i<6;i++){
colorItem = dokumen.createElement("div");
colorItem.style.backgroundColor="#"+SpColorHex[i];
colorBank.appendChild(colorItem);
}
var colorItems = colorBank.getElementsByTagName("div");
for(i=0; i<colorItems.panjang;i++){
item warna[i].onmouseover = fungsi(){
a = ini.gaya.warna latar;
if(a.panjang>7){
a = formatRgb(a);//
}
colorViews.style.background = a.toUpperCase();
colorInput.nilai = a.toUpperCase();
}
item warna[i].onclick = function(){
a = ini.gaya.warna latar;
if(a.panjang>7){
a = formatRgb(a);//
}
sekarangWarna.nilai = a.toUpperCase();
pageColorViews.style.background = a.toUpperCase();
dokumen.body.removeChild(colorBoard);
}
}
}
//fungsi format
fungsi formatRgb(rgb){
rgb = rgb.replace("rgb","");rgb = rgb.replace("(","");rgb = rgb.replace(")","");
format = rgb.split(",");
a = eval(format[0]).toString(16);
b = eval(format[1]).toString(16);
c = eval(format[2]).toString(16);
rgb = "#"+periksaFF(a)+periksaFF(b)+periksaFF(c);
fungsi pemeriksaanFF(str){
if(str.panjang == 1){
str = str+""+str;
kembalikan str;
}kalau tidak{
kembalikan str;
}
}
kembalikan RGB;
}
//dapatkan Tubuh()
fungsi getBody(){
varBody;
if (typeof document.compatMode != 'tidak terdefinisi' && document.compatMode != 'BackCompat') {
Isi = dokumen.documentElement;
}
else if (typeof document.body != 'tidak terdefinisi') {
Badan = dokumen.badan;
}
kembali Tubuh;
}
//scrollPos
fungsi getScrollPos(){
var t,l;
if (typeof window.pageYOffset != 'tidak terdefinisi'){
t = jendela.halamanYOffset;
l = jendela.halamanXOffset;
}
kalau tidak{
t = getBody().scrollTop;
l = getBody().scrollLeft;
}
kembalikan {t:t,l:l};
}
</skrip>
</kepala>
<tubuh>
<lebar tabel="500" perbatasan="1">
<tr>
<td><input type="text" value="" id="nowColor" /></td>
<td><div id="pageColorViews" style="background:#000; lebar:30px; tinggi:30px;"></div></td>
<td><a href="javascript:;" onclick="colorSelect('nowColor','pageColorViews',event)">Klik saya dan palet akan muncul</a></td>
</tr>
</tabel>
</tubuh>
</html>