62,620
社区成员
发帖
与我相关
我的任务
分享<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
</head>
<style type="text/css">
.background { background-color:Gray; width:150px; }
.word { color:red; font-size:12px; height:100px; }
</style>
<script type="text/javascript">
if (!window.getComputedStyle) {
window.getComputedStyle = function(element) {
if (!element) throw 'element is null or undefined';
if (!element.currentStyle) throw 'element unsupport currentStyle';
var cs = element.currentStyle;
!cs.getPropertyValue && (cs.getPropertyValue = function(css) {
return this[css];
});
return cs;
};
}
window.onload = function() {
var content = document.getElementById('content');
var color = window.getComputedStyle(content).getPropertyValue('background-color');
alert(color);
}
</script>
<body>
<div id="content" class="background word">test</div>
</body>
</html>