【发布时间】:2015-05-08 04:30:32
【问题描述】:
使用 JavaScript 更改元素的背景颜色最合适且跨浏览器兼容的方法是什么?
<!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>
【问题讨论】:
标签: javascript css