Altering the Background Color with JavaScript
Changing the background color of a webpage with JavaScript is a straightforward task. Here's how to do it:
Solution:
Here's a sample function to achieve this:
function changeBackground(color) { document.body.style.background = color; }
Toinvoke the function, add the following code to the page's onload event handler:
window.addEventListener("load",function() { changeBackground('red') });
Note:
Consider the page's structure. If the background is set to a specific DIV container, you need to modify its background color instead of the document body.
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!