2011-08-14 42 views

回答

3

你可以做

my_iframe_reference.contentDocument.getElementById(targetId) 

通过ID在单个帧中进行搜索。

如果要搜索所有帧,可以遍历window.frames阵列。

for(var i=0; i<window.frames.length; i++){ 
    var node = window.frames[i].contentDocument.getElementById('id'); 
    if(node) return node; 
} 
+0

谢谢,我测试了它,但得到这个错误'contentDocument是undefined'。我的浏览器是ie8 – ahoo

+0

尝试'contentWindow.document'而不是:http://stackoverflow.com/questions/1477547/getelementbyid-contentdocument-error-in-ie – hugomg

+0

frames []只返回一个'iframes'数组没有'frames' ,至少在IE中 – ahoo

相关问题