index.asp页面的内容
function SelectColor(sEL,form){
var dEL = document.all(sEL);
var url = 'selcolor.asp?color='+encodeURIComponent(sEL);
var arr = showModalDialog(url,window,'dialogWidth:280px;dialogHeight:250px;help:no;scroll:no;status:no');
if (arr) {
form.value=arr;
//sEL.style.backgroundColor=arr;
}
}
选择颜色
selcolor.asp页面内容
TD {FONT-SIZE: 10.8pt}
BODY {FONT-SIZE: 10.8pt}
BUTTON {WIDTH: 5em}
var URLParams = new Object() ;
var sAction = URLParams['action'] ;
var sTitle = "";
var color = "" ;
var oSelection;
var oControl;
var sRangeType;
// 是否有效颜色值
function IsColor(color){
var temp=color;
if (temp=="") return true;
if (temp.length!=7) return false;
return (temp.search(/\#[a-fA-F0-9]{6}/) != -1);
}
switch (sAction) {
case "forecolor": // 字体前景色
sTitle = "字体前景色";
oSelection = dialogArguments.eWebEditor.document.selection.createRange();
color = oSelection.queryCommandValue("ForeColor");
if (color) color = N2Color(color);
break;
case "backcolor": // 字体背景色
sTitle = "字体背景色";
oSelection = dialogArguments.eWebEditor.document.selection.createRange();
color = oSelection.queryCommandValue("BackColor");
if (color) color = N2Color(color);
break;
case "bgcolor": // 对象背景色
sTitle = "对象背景色";
oSelection = dialogArguments.eWebEditor.document.selection.createRange();
sRangeType = dialogArguments.eWebEditor.document.selection.type;
if (sRangeType == "Control") {
oControl = GetControl(oSelection, "TABLE");
}else{
oControl = GetParent(oSelection.parentElement());
}
if (oControl) {
switch(oControl.tagName){
case "TD":
sTitle += " – 单元格";
break;
case "TR":
case "TH":
sTitle += " – 表格行";
break;
default:
sTitle += " – 表格";
break;
}
color = oControl.bgColor;
}else{
sTitle += " – 网页";
}
break;
default: // 其它颜色框
if (URLParams['color']){
color = decodeURIComponent(URLParams['color']) ;
}
break;
}
document.write("
颜色选择(" + sTitle + ")");// 默认显示值
if (!color) color = "#000000";
// 返回有背景颜色属性的对象
function GetParent(obj){
while(obj!=null && obj.tagName!="TD" && obj.tagName!="TR" && obj.tagName!="TH" && obj.tagName!="TABLE")
obj=obj.parentElement;
return obj;
}
// 返回标签名的选定控件
function GetControl(obj, sTag){
obj=obj.item(0);
if (obj.tagName==sTag){
return obj;
}
return null;
}
// 数值转为RGB16进制颜色格式
function N2Color(s_Color){
s_Color = s_Color.toString(16);
switch (s_Color.length) {
case 1:
s_Color = "0" + s_Color + "0000";
break;
case 2:
s_Color = s_Color + "0000";
break;
case 3:
s_Color = s_Color.substring(1,3) + "0" + s_Color.substring(0,1) + "00" ;
break;
case 4:
s_Color = s_Color.substring(2,4) + s_Color.substring(0,2) + "00" ;
break;
case 5:
s_Color = s_Color.substring(3,5) + s_Color.substring(1,3) + "0" + s_Color.substring(0,1) ;
break;
case 6:
s_Color = s_Color.substring(4,6) + s_Color.substring(2,4) + s_Color.substring(0,2) ;
break;
default:
s_Color = "";
}
return '#' + s_Color;
}
// 初始值
function InitDocument(){
ShowColor.bgColor = color;
RGB.innerHTML = color;
SelColor.value = color;
}
var SelRGB = color;
var DrRGB = '';
var SelGRAY = '120';
var hexch = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
function ToHex(n) {
var h, l;
n = Math.round(n);
l = n % 16;
h = Math.floor((n / 16)) % 16;
return (hexch[h] + hexch[l]);
}
function DoColor(c, l){
var r, g, b;
r = '0x' + c.substring(1, 3);
g = '0x' + c.substring(3, 5);
b = '0x' + c.substring(5, 7);
if(l > 120){
l = l – 120;
r = (r * (120 – l) + 255 * l) / 120;
g = (g * (120 – l) + 255 * l) / 120;
b = (b * (120 – l) + 255 * l) / 120;
}else{
r = (r * l) / 120;
g = (g * l) / 120;
b = (b * l) / 120;
}
return '#' + ToHex(r) + ToHex(g) + ToHex(b);
}
function EndColor(){
var i;
if(DrRGB != SelRGB){
DrRGB = SelRGB;
for(i = 0; i <= 30; i ++)
GrayTable.rows(i).bgColor = DoColor(SelRGB, 240 – i * 8);
}
SelColor.value = DoColor(RGB.innerText, GRAY.innerText);
ShowColor.bgColor = SelColor.value;
}
SelRGB = event.srcElement.bgColor;
EndColor();
RGB.innerText = event.srcElement.bgColor;
EndColor();
RGB.innerText = SelRGB;
EndColor();
SelGRAY = event.srcElement.title;
EndColor();
GRAY.innerText = event.srcElement.title;
EndColor();
GRAY.innerText = SelGRAY;
EndColor();
color = SelColor.value;
if (!IsColor(color)){
alert('无效的颜色值!');
return;
}
switch (sAction) {
case "forecolor":
dialogArguments.format('ForeColor', color) ;
window.returnValue = null;
break;
case "backcolor":
dialogArguments.format('BackColor', color) ;
window.returnValue = null;
break;
case "bgcolor":
if (oControl){
oControl.bgColor = color;
}else{
dialogArguments.setHTML("
"+dialogArguments.getHTML()+" |
}
window.returnValue = null;
break;
default:
window.returnValue = color;
break;
}
window.close();
function wc(r, g, b, n){ r = ((r * 16 + r) * 3 * (15 – n) + 0x80 * n) / 15; g = ((g * 16 + g) * 3 * (15 – n) + 0x80 * n) / 15; b = ((b * 16 + b) * 3 * (15 – n) + 0x80 * n) / 15; document.write(' |
}
var cnum = new Array(1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0);
for(i = 0; i
document.write('
');for(j = 0; j
n1 = j % 5;
n2 = Math.floor(j / 5) * 3;
n3 = n2 + 3;
wc((cnum[n3] * n1 + cnum[n2] * (5 – n1)),
(cnum[n3 + 1] * n1 + cnum[n2 + 1] * (5 – n1)),
(cnum[n3 + 2] * n1 + cnum[n2 + 2] * (5 – n1)), i);
}
document.writeln('
');}
for(i = 255; i >= 0; i -= 8.5)
document.write('
');选中色彩
| 基色: 亮度: 120 代码: | 确定 | |
取消 |
原创文章,转载请注明来源