【问题标题】:IE8 cloneNode(true) object doesn't support this property or methodIE8 cloneNode(true) 对象不支持此属性或方法
【发布时间】:2013-06-18 16:14:49
【问题描述】:

$('#attachment-deletion').cloneNode(true);

IE 报告对象不支持此属性或方法

对此我能做些什么? cloneNode 是我对 IE8 无法识别 jquery 的克隆方法的解决方案,它甚至没有抛出错误

【问题讨论】:

  • 你试过了吗:$('#attachment-deletion')[0].cloneNode(true);?
  • 或只是$('#attachment-deletion').clone(true);
  • @roasted,元素零和转换回 jquery 对象的组合对我有用
  • 所以你能发布适合你的代码吗?!
  • @roasted var attachmentDeleteMainModalClone = $('#attachment-deletion')[0].cloneNode(true); $(attachmentDeleteMainModalClone).attr('id', 'attachment-deletion-'+'main'); 前面没有提到的是我在克隆方法之后也无法访问对象,现在它全部修复了

标签: javascript jquery clone deep-copy clonenode


【解决方案1】:

cloneNode 是一种本机 javascript 方法,它不适用于 jQuery 对象,您已经决定使用什么:

jQuery

$('#attachment-deletion').clone(true);

或者纯JS

document.getElementById('attachment-deletion').cloneNode(true);

编辑: 如果需要,您还可以将普通 JS 与 jQuery 结合使用:

$('#attachment-deletion').get(0).cloneNode(true);
// or
$('#attachment-deletion')[0].cloneNode(true);

【讨论】:

  • 将此答案与其他一些 cmets 相结合对我有用,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多