父级:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script src="js/jquery-1.11.3.js"></script>
<style>
* {padding: 0; margin: 0;}
body,html {width: 100%; height: 100%;}
</style>
</head>
<body>
<iframe id="qq" name="myFrame" src="test2.html" frameborder="0"></iframe>
</body>
<script>
;$(function() {
var x = document.getElementById('qq').contentWindow.document.getElementById('div1');
console.log(x);
});
</script>
</html>
子级:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script src="js/jquery-1.11.3.js"></script>
<style>
* {padding: 0; margin: 0;}
body,html {width: 100%; height: 100%;}
#div1 {height: 200px; background: red;}
</style>
</head>
<body>
<div id="div1">123</div>
</body>
<script>
$(function() {
})
</script>
</html>
请问为什么输出的null???
我想操作iframe里面的元素,求解决?
如果换成:
var x = $(window.frames["myFrame"].document).find("#div1").text();
console.log(x);
输出的是空值,不知道问题到底出在哪里??网上教程对不对啊