在iframe中获取父页面的元素
a.html
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <div id="a">hello world!!!</div> <div id="b"> <iframe id="frm" name="frm" src="b.html"></iframe> </div> </body> </html>
b.html
<!DOCTYPE html> <html> <head> <title></title> <script type="text/javascript" src="jquery.js" ></script> <script type="text/javascript"> function aa(){ //获取本页面的元素 //var a = document.getElementById("a12").innerHTML; //获取父页面的元素 //方法一 //var a = $(window.parent.document).find("#a").text(); //方法二 var a = $("#a",window.parent.document).text(); alert(a); } </script> </head> <body> <div id="a12">哈哈</div> <div> <div id="btn" onclick="aa()">点击</div> </div> </body> </html>