如何使用相同的ID刷新多个iframe

How can refresh multiple iframes using the same ID

本文关键字:刷新 iframe ID 何使用      更新时间:2023-09-26

如何使用相同的ID刷新多个iframe。代码示例:

<iframe id="x123"></iframe>
<iframe id="x123"></iframe>
<iframe id="x123"></iframe>

我测试

document.getElementById('x123').contentWindow.location.reload();

parent.document.getElementById('x123').contentWindow.location.reload();

第一个就在另一个上面,它不刷新。

谢谢:)

id代表身份,技术上总是唯一的。你可能指的是"相同的类别",而不是"相同的id"。

id属性改为class

<iframe class="x123"></iframe>
<iframe class="x123"></iframe>
<iframe class="x123"></iframe>

使用jquery访问元素:

$('.x123')

查找contentWindow.location.reload()对应的jquery代码