有人可以解释一下为什么这段代码不起作用。浏览器以值 vspace="0" 响应。这意味着算术表达式不正确,但为什么呢?
<script type="text/javascript">
function resizeImage()
{
var window_height = document.body.clientHeight
var window_width = document.body.clientWidth
var image_width = document.images[0].width
var image_height = document.images[0].height
var height_ratio = image_height / window_height
var width_ratio = image_width / window_width
var aspect_ratio = image_height / image_width
if (height_ratio > width_ratio)
{
document.images[0].style.width = "auto";
document.images[0].style.height = "100%";
}
else
{
var new_vspace = Math.round((window_height - window_width*aspect_ratio) / 2);
document.images[0].style.width = "100%";
document.images[0].style.height = "auto";
document.images[0].vspace="new_vspace";
}
}
</script>
</head>
<BODY bgcolor=#000000 onresize="resizeImage()">
<script>
document.write('<center><img onload="resizeImage()" margin="0" border="0" src="nweshow/picture-0011.jpg"/></center>')
</script>
</body>