日期:2014-05-16 浏览次数:20364 次
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
//IE8/IETest 6 , Firefox , Chrome 均可
function test(){
var iFrame = document.getElementById("profileFrame");
var iFrameElement = iFrame.contentWindow.document.getElementById('content');
alert(iFrameElement.innerHTML);
}
//IE8/IETest 6 , Firefox , Chrome 均可
function testJQ(){
var objHtml = $("#profileFrame").contents().find("#content").html();
alert(objHtml);
}
</script>
</head>
<body>
<div id="divM" style="width:100%;height:900px;" >
<input type="button" onclick="test()" value="js获取子页面中的元素" /><br /><br />
<input type="button" onclick="testJQ()" value="jQuery获取子页面中的元素" /><br /><br />
<iframe id="profileFrame" src="b.htm" width="300" height="300" ></iframe>
</div>
</body>
</html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="content" style="width:100%;height:900px;" >
敢取我呀,不想死了?
</div>
</body>
</html>