如何使用JavaScript更改背景颜色? [英] How do I change the background color with JavaScript?
本文介绍了如何使用JavaScript更改背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都知道使用JavaScript交换网页背景颜色的简单方法?
Anyone know a simple method to swap the background color of a webpage using JavaScript?
推荐答案
修改JavaScript属性 document.body.style.background
。
Modify the JavaScript property document.body.style.background
.
例如:
function changeBackground(color) {
document.body.style.background = color;
}
<BODY onload="changeBackground('red');">
这是纯JavaScript,与AJAX无关)
This is pure JavaScript, nothing to do with AJAX :)
注意:这确实取决于您的页面是如何组合在一起的,例如,如果您使用的DIV容器具有不同的背景颜色,您将需要修改它的背景颜色,而不是文档身体。
Note: this does depend a bit on how your page is put together, for example if you're using a DIV container with a different background colour you will need to modify the background colour of that instead of the document body.
这篇关于如何使用JavaScript更改背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文