转载自:http://www.cnblogs.com/mybest/archive/2011/12/02/2271940.html
父页面代码
<!DOCTYPE HTML>
<
html
>
<
head
>
<
meta
charset
=
"utf-8"
>
<
title
>无标题文档</
title
>
<
script
type
=
"text/javascript"
src
=
"jquery-1.4.4.min.js"
></
script
>
</
head
>
<
body
>
<
div
class
=
"f_div"
>父页面内容</
div
>
<
iframe
name
=
'if1'
src
=
"1.html"
width
=
"300"
height
=
"400"
></
iframe
>
<
script
>
$(function(){
$('iframe').load(function(){ //确保子页面完成加载
alert($('iframe').contents().find('.c_div').html());
alert($('.c_div',window.frames["if1"].document).html());//另一方法
});
});
</
script
>
</
body
>
</
html
>
|
子页面代码
<!DOCTYPE HTML>
<
html
>
<
head
>
<
meta
charset
=
"utf-8"
>
<
title
>无标题文档</
title
>
<
script
type
=
"text/javascript"
src
=
"jquery-1.4.4.min.js"
></
script
>
</
head
>
<
body
>
<
div
class
=
"c_div"
>子页面内容</
div
>
<
script
>
$(function(){
alert($('.f_div',parent.document).html());
});
</
script
>
</
body
>
</
html
>
|