Dav*_*vid 6 javascript jquery clone copy popup
这是我的第一篇文章堆栈溢出,... :)我喜欢这个网站很多!
我的问题:如何使用JQuery将元素从开始页面复制到弹出窗口?
这是我到目前为止所尝试的:
CopyToThisPageFromTheParent('#accordianResults');
function CopyToThisPageFromTheParent(querySelector) {
var clone = $(querySelector, window.parent.document).clone();
$('#testHtml').append(clone);
alert($('#testHtml').html());
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
var clone = $('#accordianResults', window.parent.document).clone();
alert($('#testHtml').html());
Run Code Online (Sandbox Code Playgroud)
谢谢!
大卫
我的 JavaScript 有两个问题。
相反,我必须使用挂在 JQuery 选择器上的 .html() 项将 HTML 从克隆中传递到 .append() 中。
这是最终的最终结果:
CopyToThisPageFromTheParent('#accordion', '#testDiv');
function CopyToThisPageFromTheParent(openingWindowSelector, childWindowSelector) {
var clone = $(openingWindowSelector, window.opener.document).clone(true);
var theOuterHtml = clone.wrap('<div></div>').parent().html();
$(childWindowSelector).append(theOuterHtml);
}
Run Code Online (Sandbox Code Playgroud)
假设我有这个 HTML:
<div id="testDiv"></div>
Run Code Online (Sandbox Code Playgroud)
在我的弹出窗口页面上,以及这个 HTML:
<div id="accordion">something</div>
Run Code Online (Sandbox Code Playgroud)
在我的主页中,使用“ window.open();”打开弹出窗口。
谢谢,大卫