我有一个奇怪的问题。 我在页面上创建了一个 iframe,现在想将其放入两个不同的容器中:
var iFrame = $('[data-id="loginWindowIframe"]');
//put the iframe in first holder
$('#loginWindow').html(iFrame);
//put the iframe to the second holder
$('[data-id="loginWindow"]').html(iFrame);
问题是,当我将 iframe 添加到第二个框架时,它已从第一个框架中完全删除。似乎我在页面上只能有一个具有相同属性的 iframe 实例...
我做错了什么?
最佳答案
你只是移动它。克隆它
var $iFrame = $('[data-id="loginWindowIframe"]');
//put the iframe in first holder
$('#loginWindow').empty().append($iFrame);
//put a clone of the iframe to the second holder
$('[data-id="loginWindow"]').empty().append($iFrame.clone());
请注意,我使用了 $iFrame
而不是 iFrame
。这纯粹是为了可读性 - 它表示它拥有一个 jQuery 对象。
关于javascript - 页面上两个地方有相同的 iframe 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22799985/