JS web page color picker

Source: Internet
Author: User
Tags javascript array
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.