代码如下
<!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>
<title></title>
<style type="text/css">
.show{
height:100px;
width:100px;
border:1px solid #333333;
background-color:#999999;
}
</style>
</head>
<body>
<div id='ss' class="show"></div>
<script language="javascript">
function CurrentStyle(element){
return element.currentStyle || document.defaultView.getComputedStyle(element, null);
};
window.onload = function(){
alert(CurrentStyle(document.getElementById("ss")).height);
alert(CurrentStyle(document.getElementById("ss")).width);
alert(CurrentStyle(document.getElementById("ss")).backgroundColor);
alert(CurrentStyle(document.getElementById("ss")).border);//ie下undefied ;ff,chrome下是空的
}
</script>
</body>
</html>
<!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>
<title></title>
<style type="text/css">
.show{
height:100px;
width:100px;
border:1px solid #333333;
background-color:#999999;
}
</style>
</head>
<body>
<div id='ss' class="show"></div>
<script language="javascript">
function CurrentStyle(element){
return element.currentStyle || document.defaultView.getComputedStyle(element, null);
};
window.onload = function(){
alert(CurrentStyle(document.getElementById("ss")).height);
alert(CurrentStyle(document.getElementById("ss")).width);
alert(CurrentStyle(document.getElementById("ss")).backgroundColor);
alert(CurrentStyle(document.getElementById("ss")).border);//ie下undefied ;ff,chrome下是空的
}
</script>
</body>
</html>
alert(CurrentStyle(document.getElementById("ss")).borderColor);
alert(CurrentStyle(document.getElementById("ss")).borderStyle);