我需要通过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之外的其他方法来运行......
答案 0 :(得分:0)
在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";
答案 1 :(得分:0)
使用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";