[英]change width of an inner Iframe that is inside 2 divs
我需要通過javascript從這樣的結構更改寬度
<div id="HTMLGroupBox742928" class="HTMLGroupBox" style="width:1366px">
<div style ="width:800px;">
<iframe id="notReliable_ChangeEveryTimeOnLoad" frambeborder="no" style="width:800px">
<html>....</html>
</iframe>
</div>
</div>
如何為內部div和iframe設置1366px的寬度? 順便說一句,iframe ID在主程序的每次加載時都會不斷變化,因此我必須使用除getelementbyid之外的其他方法來運行...
在Jquery中:
$(".HTMLGroupBox").css("width","1366px"); // targets the first div with class HTMLGroupBox and sets its width.
$(".HTMLGroupBox").find('div').css("width","1366px"); // targets the div element inside the first div with class HTMLGroupBox and sets its width.
$(".HTMLGroupBox").find('div').find('iframe').css("width","1366px"); // targets the iframe element inside the div which is inside the first div with class HTMLGroupBox and sets its width.
范例: http : //jsfiddle.net/ayL6o6v3/
在Javascript中:
document.getElementByClass("HTMLGroupBox").style.width = "1366px";
document.getElementByClass("HTMLGroupBox").getElementsByTagName('input').style.width = "1366px";
document.getElementByClass("HTMLGroupBox").getElementsByTagName('input').getElementsByTagName('iframe').style.width = "1366px";
使用JavaScript,您應該執行以下操作:
HTML:
<div id="HTMLGroupBox742928" class="HTMLGroupBox" style="width:1366px">
<!-- Use an ID on each component you want to change through JS -->
<div id="innerDiv" style ="width:800px;">
<iframe id="notReliable_ChangeEveryTimeOnLoad" frambeborder="no" style="width:800px">
<html>....</html>
</iframe>
</div>
</div>
JavaScript:
document.getElementById('innerDiv').style.width = "1366px";
document.getElementById('notReliable_ChangeEveryTimeOnLoad').style.width = "1366px";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.