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.
以上是如何使用 JavaScript 來變更網頁的背景顏色?的詳細內容。更多資訊請關注PHP中文網其他相關文章!