日期:2014-05-16 浏览次数:20911 次
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
.box{width:500px;height:800px;border:solid 1px #ccc;margin:100px auto;}
img{border:none; vertical-align:top;}
.box1{}
.box2{background:green;}
</style>
<script>
window.onload=function()
{
var oBox=document.getElementById('box');
var oImg=oBox.getElementsByTagName('img')[0];
var oBox2=oBox.getElementsByTagName('div')[1];
var img=new Image();
img.src=oImg.src+"?t="+Math.random()*1000;
img.onload=function()
{
oBox2.style.height=getStyle(oBox,'height')-this.height+'px';
}
}
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 class="box1">
<img src="http://img0.bdstatic.com/img/image/shouye/quanzhixian.jpg" alt=""/>
</div>
<div class="box2"></div>
</div>
</body>
</html>