iframe都是自动生成的,没办法给每个iframe指定专有的名称。如何列举出所有的iframe对象,并可以使用其中的变量。

解决方案 »

  1.   

    var block = document.getElementById(blockid);如何列举出所有 block 下的 iframe 
      

  2.   

    var frm = document.frames;
    for (i=0; i < frm.length; i++) alert(frm[i].xxxx);
      

  3.   

    目前是这样做的,但是不知道是不是在block里
      

  4.   

    var block = document.getElementById(blockid);
    var frm  = block.getElementsByTagName(iframe);
    for (i=0; i < frm.length; i++) alert(frm[i].contentWindow.xxxx);
      

  5.   

      跨区访问iframe内容,我知道一种方法 
      就是要多建立俩个iframe,通过另外一个iframe来访问你的iframe 
      下面是例子 
    主页面代码: 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <title>主页面 </title> 
    <script language="javascript"> 
    </script> 
    </head> 
    <iframe id="baidu" src="http://baidu.com" name="baidu" > </iframe> 
    <iframe id="google" src="getDocument2.html" name="google" > </iframe> 
    <iframe id="getD" src="getDocument.html" name="getD"> </iframe> 
    <body> 
    </body> 
    </html> 
    getDocument2.html: 
    <html> 
    <head> 
    <script> 
    window.onload = function (){ 
    alert(3); 
    alert(parent.document.frames.length); 
    alert(parent.document.frames["getD"].window.document.getElementById('up')); 
    alert(parent.document.frames["getD"].window.document.getElementById('up').innerHTML); 

    function getdocument(){ 
    alert(4); 
    alert(parent.document.frames["getD"].window.document.getElementById('up').innerHTML); 

    </script> 
    </head> 
    <body> 
    <p id='up'>getDocument2 </p> 
    <p id='element'>getElement2 </p> 
    <input type="button" onclick="getdocument();" value="获取iframe"/> 
    </body> 
    </html> 
    getDocument.html: 
    <html> 
    <head> 
    </head> 
    <body> 
    <p id='up'>getDocument </p> 
    <p id='element'>getElement </p> 
    </body> 
    </html> 
    自己运行就可以了
      

  6.   

    多谢 hookee!
    一会儿结帖,要是上不了网就明天结。
    帮忙看下这个:http://topic.csdn.net/u/20090718/15/b8ff6bd9-1f60-43bb-bf31-366282fd8f3b.html?seed=1816260280&r=58530188#r_58530188