JS: How to customize the background color on the page at any time. js background color

Source: Internet
Author: User

JS: How to customize the background color on the page at any time. js background color

This example describes how to customize the background color on the page in JavaScript. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is as follows: <HTML>
<HEAD>
<TITLE> customize the background color on the page in Javascript </TITLE>
<Script language = "JavaScript">
<! -- Begin
// The following code writes the input box and Its layer into the window.
Document. writeln ('<div align = "center" id = bgcolortestdiv style = "BACKGROUND-COLOR: gray; POSITION: absolute; width: 200; height: 70; top = 100; Z-INDEX: 100 "> ');
Document. writeln ('<p> <B> <font size = 2> enter the color code <br> You can instantly change the background color </font> </B> </p> ');
Document. writeln ('<p> <input type = "text" name = "text" onkeyup = "cbgcolor (this. value)"> </p> ');
Document. writeln ('</div> ');
Function cbgcolor (color) {// change background color
If (color! = '')
Document. bgColor = (''+ color +''); // you can specify the background color.
}
Function keepdivpos () {// keep div position
Document. all. bgcolortestdiv. style. pixelTop = parseInt (document. body. scrollTop) + 100 // calculate and set the relative position of the layer
}
SetInterval ('keepdivpos () ', 100) // set the clock that automatically changes the layer position.
// End -->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

I hope this article will help you design javascript programs.

Related Article

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.