文章目录
HTML DOM backgroundColor 属性
HTML DOM Style 对象参考手册
定义和用法
backgroundColor 属性设置元素的背景颜色。
语法:
Object.style.backgroundColor=color-name|color-rgb |color-hex|transparent
实例
本例设置 body 的背景色:
<html>
<head>
<style type="text/css">
body
{
background-color:#B8BFD8;
}
</style>
<script type="text/javascript">
function changeStyle()
{
document.body.style.backgroundColor="#FFCC80";
}
</script>
</head>
<body>
<input type="button" onclick="changeStyle()"
value="Change background color" />
</body>
</html>
TIY
- 改变背景色(十六进制)
- 改变背景色(颜色名)
HTML DOM Style 对象参考手册