js颜色选择器代码[firefox不支持]
<OBJECT id="dlgHelper" CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0" height="0"></OBJECT>
<script type="text/javascript">
var tempColor = "0099cc";
function picColor(){
var Hcolor = document.getElementById("dlgHelper").ChooseColorDlg(tempColor).toString(16);
//with(event.srcElement){
//value = ((Hcolor.length<6)?"000000".substring(0,6-Hcolor.length):"") + Hcolor;
//style.backgroundColor = ((Hcolor.length<6)?"000000".substring(0,6-Hcolor.length):"") + Hcolor;
var newColor = ((Hcolor.length<6)?"000000".substring(0,6-Hcolor.length):"") + Hcolor;
if(newColor.toString().substring(0,1) != "#"){
newColor = "#" + newColor;
}
alert(newColor);
}
// tempColor = Hcolor;
// window.alert(tempColor);
//}
</script>
或者直接使用这个:
颜色选择器
document.write("");
var ocolorPopup = window.createPopup();
var ecolorPopup=null;
function colordialogmouseout(obj){
obj.style.borderColor="";
obj.bgColor="";
}
function colordialogmouseover(obj){
obj.style.borderColor="#0A66EE";
obj.bgColor="#EEEEEE";
}
function colordialogmousedown(color){
ecolorPopup.value=color;
//document.body.bgColor=color;
ocolorPopup.document.body.blur();
}
function colordialogmore(){
var sColor=dlgHelper.ChooseColorDlg(ecolorPopup.value);
sColor = sColor.toString(16);
if (sColor.length ";
ocbody += "
";
for(var i=0;i";
ocbody += "
";
if(i%8==7)
ocbody += "
";
}
ocbody += "
";
ocbody += "
";
//www.jb51.net 我们
oPopBody.innerHTML=ocbody;
ocolorPopup.show(e.offsetLeft, e.offsetTop+e.offsetHeight, 158, 147, document.body);
}
//-->
选择颜色:
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]