js设置div高度为浏览器一半

<body onload="init()">
<div id="test">
 
</div>
</body>
<javascript>
function init() {
var totalHeight = window.innerHeight || document.body.clientHeight
var testObj= document.getElementById('test')
var halfHeight= totalHeight  / 2
testObj.style.height = halfHeight+ 'px'
}
</javascript>

猜你喜欢

转载自www.cnblogs.com/xujuntao/p/12325985.html
今日推荐