W3C的标准告诉我们,可以通过Dom对象的contentDocument属性来返回文档对象。
var
doc = document.getElementById(
'mainFrame'
).contentDocument
|
IE8开始支持,如果你的项目不用兼容IE6,IE7的话使用这种方式最好。
IE6,IE7需要如此访问
var
doc = document.frames[
'mainFrame'
].document;
|
兼容方式:
var
doc = document.getElementById(
'mainFrame'
).contentDocument || document.frames[
'mainFrame'
].document;
|
以上是Javascript原生方法:
使用Jquery则简单些
$(
"iframe"
).contents().find(
"selector"
)
|
试试这样写:
$(
'#frameID'
).load(
function
() {
$(
'#frameID'
).contents().find(
'a'
);
//以iframe中找元素a为例
});