如题,父容器<div id='father'></div>中嵌入一个iframe,iframe中有一个子元素<div id='child'></div>,js或者jquery怎么通过#father找到#child? 直接写好像是不行的..
谢谢!
如题,父容器<div id='father'></div>中嵌入一个iframe,iframe中有一个子元素<div id='child'></div>,js或者jquery怎么通过#father找到#child? 直接写好像是不行的..
谢谢!
<html>
<head>
<title>1.html</title>
</head>
<body>
<input type="button" onClick="show()" value="2.html的内容">
<iframe src="new_file2.html" name="myframe"></iframe>
</body>
<script type="text/javascript">
function show() {
var xx = window.frames["myframe"].document.getElementById("bd").innerHTML;
console.log(xx)
}
</script>
</html>
<html>
<head>
<title>2.html</title>
</head>
<body id="bd">
111 <br />
</body>
</html>
window.frames 返回一个类数组对象,返回当前窗口的所有子框架元素.
window.frames[0].document.querySelector("#child");
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答5.1k 阅读✓ 已解决
5 回答1.9k 阅读
当然了, 因为是两个页面, 应该先找到iframe的 document然后再找#child