代码示例:(标识:jsck_style_backgroundcolor_2)
<!DOCTYPE html>
<html>
<head>
<style> 
#myDIV {
  width: 300px;
  height: 300px;
  background-color: coral;
  color: white;
}
</style>
</head>

<body>

<h1>HTML Style 对象</h1>

<h2>backgroundColor 属性</h2>

<p>请点击“试一试”按钮,将 DIV 元素的 backgroundColor 属性设置为 “lightblue”:</p>

<button onclick="myFunction()">试一试</button>

<div id="myDIV">
  <h1>Hello</h1>
</div>

<script>
function myFunction() {
  document.getElementById("myDIV").style.backgroundColor = "lightblue";
}
</script>

</body>
</html>
运行结果: