日期:2014-05-16 浏览次数:20675 次
<!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>无标题文档</title>
<style>
.box{width:500px;height:100px;background:#6FF;position:absolute;left:30px;}
</style>
<script>
window.onload=function()
{
var oBox=document.getElementById('box');
alert(getStyle(oBox,'left'));
}
function getStyle(obj,attr)
{
if(obj.currentStyle)
return parseFloat(obj.currentStyle[attr])
------解决方案--------------------
0;
return parseFloat(getComputedStyle(obj,0)[attr])
------解决方案--------------------
0;
}
</script>
</head>
<body>
<div class="box" id="box">
</div>
</body>
</html>