---
<div id="colorWrapper"></div>
<script type="text/javascript">
var colors=["00","33","66","99","CC","FF","00","33","66","99","CC","FF"];
function createColor(rows,cols){
var color,output=[´<table cellpadding="0" cellspacing="1" border="0" bgcolor="#333333"><tbody>´];
for(var r=0;r<rows;r++){
output.push(´<tr>´);
for(var c=0;c<cols;c++){
color = r<6?"#"+colors[Math.floor(c/6)]+colors[Math.floor(c%6)]+colors[r]:"#"+colors[Math.floor(c/6)+3]+colors[Math.floor(c%6)]+colors[r-6];
output.push(´<td unselectable="on" style="width:10px;height:10px;background:´+color+´;cursor:pointer" onclick="getColor(´´+color+´´);"></td>´);
}
output.push(´</tr>´);
}
output.push(´</tbody></table>´);
return output.join(´´);
}
function getColor(color){
alert(color);
}
document.getElementById(´colorWrapper´).innerHTML=createColor(12,18);
</script>
查看Demo