简体   繁体   English

更改2格内的内部iframe的宽度

[英]change width of an inner Iframe that is inside 2 divs

I need to change through javascript a width from an structure like this 我需要通过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>

How can i set a width of 1366px for both the inner div and the iframe ? 如何为内部div和iframe设置1366px的宽度? btw, the iframe Id keep changing on every load from the master program, so i gotta run around using other methods than getelementbyid... 顺便说一句,iframe ID在主程序的每次加载时都会不断变化,因此我必须使用除getelementbyid之外的其他方法来运行...

In Jquery : 在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.

Example : http://jsfiddle.net/ayL6o6v3/ 范例: http//jsfiddle.net/ayL6o6v3/

In Javascript : 在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";

Example : http://jsfiddle.net/ayL6o6v3/1/ 范例: http//jsfiddle.net/ayL6o6v3/1/

Using JavaScript, you should be doing something like this: 使用JavaScript,您应该执行以下操作:

HTML: 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: JavaScript:

document.getElementById('innerDiv').style.width = "1366px";
document.getElementById('notReliable_ChangeEveryTimeOnLoad').style.width = "1366px";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM