简体   繁体   中英

Fastest way to change page background color using JS?

What's the smallest and fastest way to modify a document's background color using javascript? it should be cross browser.

I tried the following which didn't work in firebug:

   document.body.bgcolor = "#eee";

   document.documentElement.bgcolor = "#eee";

使用backgroundColor CSS属性:

document.body.style.backgroundColor = "#eeeeee";

This should work:

document.body.style.backgroundColor = "#eee";

Here is a live demo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM