This article describes the method of JS to customize background colors at any time on the page. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows: <HTML>
<HEAD>
<TITLE>JS implements custom background color at any time on the page</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>Can change the background color in real time</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+''); //Set 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 be helpful to everyone's JavaScript programming.