您好我想根据屏幕的大小来设置iframe的css高度,但我不知道如何做到这一点。使用javascript设置iframe的高度
CSS:
#iframeplate{
width:100%;
height:200px;
}
HTML:
<body onload="setGround()">
<iframe id="iframeplate" class="idIframe" frameborder=0 border=0 width="100%" scrolling-y="no" src="#">
</iframe>
</body>
JS:
<script type="text/javascript">
function setGround() {
var groundElement = document.getElementById('iframeplate');
groundElement.style.height = getWindowHeight() + 'px';
}
}
</script>
任何人都可以明白为什么这是行不通的?或者有更好的方法来做到这一点?
你有没有看任何的右侧类似的问题? – mplungjan
你的JS代码中有一个额外的“}”。你的函数“getWindowHeight()”是否返回一些东西? – khomyakoshka