<!DOCTYPE html>
<html>
<head>
<title>getStyleFunction</title>
</head>
<script type="text/javascript">
function getStyle(obj,name)
{
if (obj.currentStyle)
{
return obj.currentStyle[name];
}
else
{
return getComputedStyle(obj,false)[name];
}
}
window.onload=function()
{
var oDiv=document.getElementById('div1');
alert(getStyle(oDiv,'height'));
}
</script>
<style type="text/css">
#div1{
width: 100px;
height: 100px;
background-color: green;
}
</style>
<body>
<div id="div1"></div>
</body>
</html>
网友评论