HTML DOM backgroundColor 属性

定义和用法

backgroundColor 属性设置元素的背景颜色。

语法:

  1. Object.style.backgroundColor=color-name|color-rgb
  2. |color-hex|transparent

实例

本例设置 body 的背景色:

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. body
  5. {
  6. background-color:#B8BFD8;
  7. }
  8. </style>
  9. <script type="text/javascript">
  10. function changeStyle()
  11. {
  12. document.body.style.backgroundColor="#FFCC80";
  13. }
  14. </script>
  15. </head>
  16. <body>
  17.  
  18. <input type="button" onclick="changeStyle()"
  19. value="Change background color" />
  20.  
  21. </body>
  22. </html>