SoFunction
Updated on 2025-04-09

JS method to customize background color at any time on the page

<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.
('<div align="center" id=bgcolortestdiv style="BACKGROUND-COLOR: gray;POSITION: absolute;width: 200; height: 70; top=100; Z-INDEX: 100" >');
('<p><B><font size=2>Enter the color code<br>Can change the background color in real time</font></b></p>');
('<p><input type="text" name="text" onkeyup="cbgcolor()"></p>');
('</div>');
function cbgcolor(color){   //change background color
 if (color != '')
=(''+color+'');  //Set background color
}
function keepdivpos(){    //keep div position
=parseInt()+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>