How to customize the background color at any time on the page using JS
This article mainly introduces how to customize the background color of javascript on the page at any time. The example analyzes the javascript css style operation skills and has some reference value. If you need it, you can refer
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:
The 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.