<!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=utf-8" />
<title>JS获取CSS属性值</title>
<style type="text/css">
<!--
.ss{background:blue; color:#cdcdcd; width:200px}
-->
</style>
<link href="styles_red.css" rel="stylesheet"/>
</head>
<body>
<div id="qq" class="divtitle">sdf</div>
<script type="text/javascript">
function GetCurrentStyle (obj, prop) {
if (obj.currentStyle) {
return obj.currentStyle[prop];
}else if (window.getComputedStyle) {
propprop = prop.replace (/([A-Z])/g, "-$1");
propprop = prop.toLowerCase ();
return document.defaultView.getComputedStyle (obj,null)[prop];
}
return null;
}
var dd=document.getElementById("qq");
alert(GetCurrentStyle(dd,"color"));
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS获取CSS属性值</title>
<style type="text/css">
<!--
.ss{background:blue; color:#cdcdcd; width:200px}
-->
</style>
<link href="styles_red.css" rel="stylesheet"/>
</head>
<body>
<div id="qq" class="divtitle">sdf</div>
<script type="text/javascript">
function GetCurrentStyle (obj, prop) {
if (obj.currentStyle) {
return obj.currentStyle[prop];
}else if (window.getComputedStyle) {
propprop = prop.replace (/([A-Z])/g, "-$1");
propprop = prop.toLowerCase ();
return document.defaultView.getComputedStyle (obj,null)[prop];
}
return null;
}
var dd=document.getElementById("qq");
alert(GetCurrentStyle(dd,"color"));
</script>
</body>
</html>