欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js 颜色选择器(兼容firefox)

程序员文章站 2022-06-19 19:47:18
复制代码 代码如下:

复制代码 代码如下:

<!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">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>颜色选择器</title>
<style type="text/css">
body{
    text-align:center;
}
</style>
</head>
<body>
<p>
<script type="text/javascript" language="javascript">
<!--
var colorhex=new array('00','33','66','99','cc','ff')
var spcolorhex=new array('ff0000','00ff00','0000ff','ffff00','00ffff','ff00ff')
var current=null
function initcolor(evt)
{
var colortable=''
for (i=0;i<2;i++)
{
for (j=0;j<6;j++)
{
colortable=colortable+'<tr height=15>'
colortable=colortable+'<td width=15 style="background-color:#000000">'
if (i==0){
colortable=colortable+'<td width=15 style="cursor:pointer;background-color:#'+colorhex[j]+colorhex[j]+colorhex[j]+'" onclick="doclick(this.style.backgroundcolor)">'}
else{
colortable=colortable+'<td width=15 style="cursor:pointer;background-color:#'+spcolorhex[j]+'" onclick="doclick(this.style.backgroundcolor)">'}
colortable=colortable+'<td width=15 style="background-color:#000000">'
for (k=0;k<3;k++)
{
for (l=0;l<6;l++)
{
colortable=colortable+'<td width=15 style="cursor:pointer;background-color:#'+colorhex[k+i*3]+colorhex[l]+colorhex[j]+'" onclick="doclick(this.style.backgroundcolor)">'
}
}
}
}
colortable='<table border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 solid;border-bottom:none;border-collapse: collapse;width:337px;" bordercolor="000000">'
+'<tr height=20><td colspan=21 bgcolor=#ffffff style="font:12px tahoma;padding-left:2px;">'
         +'<span style="float:left;color:#999999;">搜索吧|为站长提供专业知识搜索</span>'
         +'<span style="float:right;padding-right:3px;cursor:pointer;" onclick="colorclose()">×关闭</span>'
+'</td></table>'
+'<table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="000000" style="cursor:pointer;">'
+colortable+'</table>';
document.getelementbyid("colorpane").innerhtml=colortable;
var current_x = document.getelementbyid("inputcolor").offsetleft;
var current_y = document.getelementbyid("inputcolor").offsettop;
//alert(current_x + "-" + current_y)
document.getelementbyid("colorpane").style.left = current_x + "px";
document.getelementbyid("colorpane").style.top = current_y + "px";
}
function doclick(obj){
    alert(obj);
}
function colorclose(){
    document.getelementbyid("colorpane").style.display = "none";
    //alert("ok");
}
function coloropen(){
    document.getelementbyid("colorpane").style.display = "";
}
window.onload = initcolor;
</script>
</p>
<p> </p>
<p> </p>
<p> </p>
<p>
<input type="button" value="颜色选择" onclick="coloropen(event)" id="inputcolor" />
</p>
<p>  </p>
<div id="colorpane" style="position:absolute;z-index:999;display:none;"></div>
</body>
</html>