是不是这个iframe还没load出来?--------------------------------------------如果你怀疑这方面原因可以等页面加载完 再手动设置样式试试

解决方案 »

  1.   

    document.frames('framename').Document.getElementById('hrefname').style.height='1000px'
      

  2.   

    如果是加载问题用defer="true"属性试试看
    <script defer="true">
       ....
       document.frames['framename'].document.xxxxx
    </script>
      

  3.   

    测试通过:<body onload="chgHeight()"> 
    <iframe id="framename" src="1.htm"></iframe>
    <script>
    function chgHeight()
    {
        framename.document.getElementById("objid").style.height="1000px";
    }
    </script>
    </body> 
      

  4.   

    <iframe id="framename" src=""></iframe><script type="text/javascript">
      window.framename.document.all["hrefname"].style.height="1000px";
    </script>
      

  5.   

    我把完整代码写出来吧:
    index.html:
    <html>
    <head>
    <script defer="true"> 
       document.frames('framename').Document.getElementById('divname').style.height='1000px'
    </script>
    </head>
    <body>
       document.write('<iframe id=framename src=1.html></iframe>');
    </body>
    </html>1.html:
    <html>
    <head>
    <body>
    <div id="linkname">content></a>
    </body>
    </html>按照楼上同学的方法加了defer属性,但是还是无法修改该div的高度
      

  6.   

    我把完整代码写出来吧: 
    index.html: 
    <html> 
    <head> 
    <script defer="true">  
       document.frames('framename').Document.getElementById('divname').style.height='1000px' 
    </script> 
    </head> 
    <body> 
       document.write(' <iframe id=framename src=1.html> </iframe>'); 
    </body> 
    </html> 1.html: 
    <html> 
    <head> 
    <body> 
    <div id="divname">content> </a> 
    </body> 
    </html> 按照楼上同学的方法加了defer属性,但是还是无法修改该div的高度
      

  7.   

    以下测试通过:
    index.html<html>
    <body onload="chgHeight()"> 
    <script language="javascript">
    document.write("<iframe id=framename src=\"1.html\"></iframe>"); 
    function chgHeight()
    {
        framename.document.getElementById("divname").style.height="1000px";
    }
    </script>
    </body> 
    </html>
    1.html<html>  
    <head>  
    <body>  
    <div id="divname">content </div>  
    </body>  
    </html>
      

  8.   

    如果你不确定是否加载完毕 简单可以这样写
     if(document.frames('framename').contentDocument.getElementById('hrefname'))
        document.frames('framename').contentDocument.getElementById('hrefname').style.height='1000px';
      

  9.   


    <html> 
    <head> 
    <script defer="true">
    window.onload=function(){alert();
       document.frames['framename'].document.getElementById('divname').style.height='1000px'
    }
    </script>
    </head> 
    <body>
    <script>
       document.write("<iframe name='framename' id='framename' src='1.html'><\/iframe>");
    </script>
    </body> 
    </html><html> 
    <head> 
    <body> 
    <div id="divname">content</div> 
    </body> 
    </html>
      

  10.   

    如果是高度自适应问题请参考:
    http://topic.csdn.net/t/20061026/21/5112244.html
      

  11.   

    基本概念:任何函数体外的代码会被立刻执行,因为你执行第一条js的时候,还没这个iframe,会报错。当然,用defer属性也可延迟执行。