Online input RGB Change background color

Source: Internet
Author: User

Html:

<! DOCTYPEHtml>
<Html>

<Head>
<Metahttp-equiv="Content-type"Content="Text/html; Charset=utf-8 "/>
<Title>RGB Color Conversion </Title>
<ScriptLanguage="JavaScript" >

functionShowrgb (obj) {
Where red, green, and blue are the name values for the input box
VarORed=Obj.red.value;
VarOgreen=Obj.green.value
VarOblue=Obj.blue.value;
Converts RGB to 16 hex value, string
Ohexcode="#"+Tohex (oRed)+Tohex (Ogreen)+Tohex (Oblue);
VarOdiv= document.getElementById ("Div");
The background color of the div =name the value of the =16 background color for the value of the Hexval input box
ODiv.style.background=Obj.hexval.value= Ohexcode;
}

functionTohex (D) {
If the input is not a number
if (IsNaN (D)) {
D=0;
}
16 Binary Conversion method
VarN= new Number (D).ToString (16);
Return (N.length==1?"0"+N:n);
}
</Script>

</Head>

<Body>
<Formstyle="Border1PX Blue solid;">
<B>Please enter an RGB color value (0 to 255) </b><Br>
Red: <InputType="Text"Name="Red"Size="5" ><Br>
Green: <InputType="Text"Name="Green"Size="5" ><Br>
Blue: <InputType="Text"Name="Blue"Size="5" ><Br>
<buttononclick="Showrgb (This.ParentNode)"Type="Button" >Show Hex #</Button>
Hex value is: <InputType="Text"Name="Hexval"Size="7" >

</Form>
<DivId="Div"style="margin: +px; Width: px; Height: px; border: 1px solid red; ></div>

</body>

</html>

Result

Online input RGB Change background color

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.