日期:2014-05-17  浏览次数:20689 次

这里为什么 无法获取 宽 高
www.style.width=document.body.offsetWidth;
www.style.height=document.body.offsetHeight;
断点以上两行

document.body.offsetWidth
document.body.offsetHeight
都有确定的值
但就是没法赋给width 和 height



<style>
#www{
background-color:#0F0;
}
</style>
<script>
function fun(){
var www=document.getElementById('www') ;
www.style.width=document.body.offsetWidth;
www.style.height=document.body.offsetHeight;
www.style.opacity=0.5;
}
</script>
</head>
<body>
<div id="www" onclick="fun()">
哇哈哈
</div>


求教

------解决方案--------------------
把你的JS函数改成下面的就行了:

function fun()
{
var www = document.getElementById('www');
www.style.width = document.body.offsetWidth+'px';
www.style.height = document.body.offsetHeight+'px';
www.style.opacity = 0.5;

}