扫码关注官方订阅号
如题,父容器<p id='father'></p>中嵌入一个iframe,iframe中有一个子元素<p id='child'></p>,js或者jquery怎么通过#father找到#child? 直接写好像是不行的..谢谢!
闭关修行中......
当然了, 因为是两个页面, 应该先找到iframe的 document然后再找#child
$('#iframe的ID').contents().find('#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>
<head> <title>2.html</title> </head> <body id="bd"> 111 <br /> </body>
window.frames 返回一个类数组对象,返回当前窗口的所有子框架元素.
window.frames[0].document.querySelector("#child");
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
当然了, 因为是两个页面, 应该先找到iframe的 document然后再找#child
$('#iframe的ID').contents().find('#child')
<html>
</html>
<html>
</html>
window.frames 返回一个类数组对象,返回当前窗口的所有子框架元素.