【发布时间】:2012-12-04 13:49:20
【问题描述】:
当我需要克隆 div 元素时,我使用getElementById。
代码:
printHTML( document.getElementById("div_name").cloneNode(true));
现在我需要使用getElementsByClassName
使用getElementsByClassName 时,CloneNode 不工作。
我怎样才能在这里输入班级名称?
谢谢
编辑:
当我尝试使用这个时:
printHTML( $('.dataTables_scroll').clone(true) );
你可以看到我的功能:
function printHTML(clonedDive){
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
iframe.contentWindow.onunload = function(){
$(".DTTT_container").show("fast");
$("#header_outer").show("fast");
$(".ColVis.TableTools").show("fast");
$("#footer").show("fast");
};
iframe.contentWindow.document.body.appendChild(clonedDive);
iframe.contentWindow.print();
document.body.removeChild(iframe);
}
我在这一行遇到错误:
iframe.contentWindow.document.body.appendChild(clonedDive);
这是一个错误描述:
Uncaught Error: NOT_FOUND_ERR: DOM Exception 8
【问题讨论】:
-
为什么当你使用 getElement 时它被标记为 jQuery...? jQuery 解决方案很简单,但不使用这些函数。
-
当您使用并要求我们使用原生 DOM 方法时,为什么要标记
jquery? -
查看更新后的问题
-
由于您已经在项目中包含了 jQuery,我建议您使用 jQuery 按类名获取元素,因为 IE 直到版本 9 才支持原生
getElementsByClassName:quirksmode.org/dom/w3c_core.html#fivemethods跨度>
标签: javascript jquery html dom clone