Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 javascript 中获取文档的孙子 div 和 iframe?我有 div 的 id 和 iframe 的名称
利用.querySelectorAll()
.querySelectorAll()
例子:
document.querySelectorAll("#iframeId .someSelector");
如果您有孩子的 ID,您可以使用它:
document.getElementById("divId");
或者您可以使用如下选择器的组合:
document.querySelectorAll("#iframeId > .someSelector > *");