<script>
function getMapSize(){
var img =document.getElementById("img")
var width =document.getElementById("mainMapDiv").offsetWidth
var height =document.getElementById("mainMapDiv").offsetHeight
img.style.width=width+"px"
img.style.height=height+"px"
}
</script>
<body onload="getMapSize()"> <form action="home.jsp" name="mainHome" id="mainHome">
<div id="mainMapDiv" style="width:500px; height:500px; border:1px solid #000000" >
<img id="img" src="http://img1.qq.com/news/pics/13589/13589082.jpg" ></div>
</form>
</body>
function getMapSize(){
var img =document.getElementById("img")
var width =document.getElementById("mainMapDiv").offsetWidth
var height =document.getElementById("mainMapDiv").offsetHeight
img.style.width=width+"px"
img.style.height=height+"px"
}
</script>
<body onload="getMapSize()"> <form action="home.jsp" name="mainHome" id="mainHome">
<div id="mainMapDiv" style="width:500px; height:500px; border:1px solid #000000" >
<img id="img" src="http://img1.qq.com/news/pics/13589/13589082.jpg" ></div>
</form>
</body>
写成img.style.height=height+2+"px"
有些误差说不清楚
+2后改变div的大小还是完全填充的......