1

こんにちは、画面の大きさに基づいてiframeのCSSの高さを設定したいのですが、これを行う方法がわかりません。

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>

なぜこれがうまくいかないのか誰にもわかりますか?または、それを行うためのより良い方法に関するアイデアはありますか?

4

3 に答える 3

3

エラーは の方法でgetWindowHeight、出力はありません。

これを試して:

groundElement.style.height = window.screen.availHeight + 'px';
于 2012-09-11T05:57:25.277 に答える
1

構文エラー。これを試して:

<iframe id="iframeplate" class="idIframe" frameborder=0 border=0 width="100%" scrolling-y="no" src="#"></iframe>


<script type="text/javascript">
function setGround() { 
    var groundElement = document.getElementById('iframeplate'); 
    groundElement.style.height = getWindowHeight() + 'px'; 
}
</script>
于 2012-09-11T05:14:18.210 に答える
0

あなたはそれを試すことができます

<body onload="setGround()">
<iframe id="iframeplate" class="idIframe"  frameborder=0 border=0   width="100%"  scrolling-y="no"  src="#"
    </iframe>

JQueryを次のように使用します

$("iframe[id='iframeplate']").height(getWindowHeight());
于 2012-09-11T05:10:49.633 に答える