什麼是使用JavaScript更改元素背景顏色的最合適和跨瀏覽器兼容的方式?使用JavaScript HTML更改背景色的最佳方式DOM DOM
<!DOCTYPE html>
<html>
<head>
<title>Demo page</title>
</head>
<body>
<h1 id="head1" style="background-color:red">This is a heading</h1>
<script>
// this one?
document.getElementById("head1").style["background-color"] = "yellow";
// this one?
document.getElementById("head1").style.backgroundColor = "yellow";
//or this one?
document.getElementById("head1").style.background = "yellow";
</script>
</body>
</html>
研究:http://stackoverflow.com/questions/19943118/difference-between-body-style-backgroundcolor-and-window-getcomputedstylebody – developerCK
謝謝你的評論。 –