This article mainly introduces how to implement the background color that changes at any time in javascript. it is very simple and practical and can be taken away directly by a small partner in need. A simple piece of code that changes the background color at any time
DocumentScript window. onload = function () {var variable = document. getElementById ('dv '); comment. style. backgroundColor = 'red' setInterval (function () {var arrRandNumber = [getRandomNumber (0,255), getRandomNumber (0,255), getRandomNumber (0,255)]; random. style. backgroundColor = 'rgb ('+ arrRandNumber [0] +', '+ arrRandNumber [1] +', '+ arrRandNumber [2] +') 'function getRandomNumber (rMin, rMax) {var cha = rMax-rMin; var rand = Math. random (); // return (rMin + Math. round (cha * rand) }}, 500) // alert (getRandomNumber (0,255)}; script
The above is all the content shared in this article. I hope it will help you learn how to use javascript.