In this example, only 216 safe colors are used, that is, the so-called Netscape color block. These 216 colors represent the five colors 0, 51, 102,153,204 and each primary color (red, green, blue ). when implementing the web page color picker, you need to apply the Javascript array,
Create a page, add a Textbox Control, set a custom onclick event for this control, and call the JavaScript function colorpick (). The Code is as follows:
<Asp: textbox id = "textbox1" runat = "server" readonly = "true" size = "3" style = "background-color: #000000 "width =" 67px "Height =" 13px "onclick =" colorpick (this) "> </ASP: textbox>
The custom JavaScript function code is as follows:
<Script language = "JavaScript">
Function colorpick (field ){
VaR RTN = Window. showmodaldialog ("default2.aspx", "", "dialogwidth: 225px; dialogheight: 170px; Status: No; help: No; scrolling = no; scrollbars = No ");
If (RTN! = NULL)
Field. style. Background = RTN;
Return;
}
</SCRIPT>
The HTML code of default2.aspx called by the above function is as follows:
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Script language = "JavaScript">
<! --
VaR H = new array (6)
H [0] = "FF ";
H [1] = "cc ";
H [2] = "99 ";
H [3] = "66 ";
H [4] = "33 ";
H [5] = "00 ";
Function action (RGB ){
// Alert ('the color you selected is: # '+ RGB );
Parent. Window. returnvalue = "#" + RGB;
Window. Close ();
}
Function mcell (R, G, B ){
Document. Write ('<TD bgcolor = "#' + R + G + B + '"> ');
Document. Write ('<a href = "#" onclick = "Action (/'' + (R + G + B) +'/') "> ');
Document. Write (' ');
Document. Write ('</a> ');
Document. Write ('</TD> ');
}
Function MTR (R, B ){
Document. Write ('<tr> ');
For (VAR I = 0; I <6; ++ I ){
Mcell (R, H [I], B );
}
Document. Write ('</tr> ')
}
Function mtable (B ){
Document. Write ('<Table cellpadding = 0 cellspacing = 0 border = 0> ');
For (VAR I = 0; I <6; ++ I ){
MTR (H [I], B );
}
Document. Write ('</table> ');
}
Function Mcube (){
Document. Write ('<Table cellpadding = 0 cellspacing = 0 border = 0> <tr> ');//
For (VAR I = 0; I <6; ++ I ){
If (I % 3 = 0 ){
Document. Write ('<tr> ');
}
Document. Write ('<TD bgcolor = "# ffffff"> ');
Mtable (H [I])
Document. Write ('</TD> ');
}
If (I % 3 = 0 ){
Document. Write ('</tr> ');
}
Document. Write ('</tr> </table> ');
}
Mcube ()
-->
</SCRIPT>
</Body>
</Html>