- <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
- <html xmlns=“http://www.w3.org/1999/xhtml”>
- <head>
- <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />
- <title>js获取iframe中元素实例</title>
- </head>
- <body>
- <script src=“http://libs.baidu.com/jquery/1.9.0/jquery.js”></script>
- <iframe id=“if” src=“index.html” width=“1200”></iframe>
- <P></P>
- <button id=“getIframe”>获取内容</button>
- <script type=“text/javascript”>
- window.onload= function(){
- var btn = document.getElementById(“getIframe”);
- var adiv = document.getElementById(“if”).contentWindow.document;
- var bdiv = adiv.getElementById(“fix”);
- btn.onclick= function(){
- alert(bdiv.innerHTML);
- }
- }
- </script>
- </body>
- </html>
index.html中代码
- <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
- <html xmlns=“http://www.w3.org/1999/xhtml”>
- <head>
- <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />
- <title>标题</title>
- </head>
- <body>
- <img src=“index.jpg” style=“text-align:center” /><br/>
- <p style=“text-align:center” id=“fix”>我是内容</p>
- </body>
- </html>