js颜色选择器代码[firefox不支持]
作者:
非常不错的,颜色选择效果代码
最简单的,在body区域加入:
<OBJECT id="dlgHelper" CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0" height="0"></OBJECT>
调用的JS:
<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>
或者直接使用这个:
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
复制代码 代码如下:
<OBJECT id="dlgHelper" CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0" height="0"></OBJECT>
调用的JS:
复制代码 代码如下:
<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>
或者直接使用这个:
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]