在执行以下代码时,IE会抛出错误-- Object不支持此属性或方法--引用cloneNode()方法。'i‘是循环计数器,source和dest都是HTML select元素。
dest.options[dest.options.length] = source.options[i].cloneNode( true );FF和Chrome的行为与预期一致。关于如何让IE执行cloneNode()有什么想法吗?IE8调试器显示source.optionsi确实有一个cloneNode()方法。
谢谢。
发布于 2010-09-07 09:28:17
IE需要
new Option()构造。
document.createElement( 'option' );或
cloneNode()都会失败。当然,所有选项在合适的web浏览器中都能正常工作。
发布于 2010-09-10 09:12:33
实际上,cloneNode没有抛出任何错误。将代码分解为较小的块,以正确识别错误的来源:
var origOpt = source.options[i];
var clonedOpt = origOpt.cloneNode( true ); // no error here
var destOptLength = dest.options.length;
dest.options[destOptLength] = clonedOpt; // error!
dest.options.add(clonedOpt); // this errors too!
dest.appendChild(clonedOpt); // but this works!或者,把它放回原来的样子,全部放在一行上:
dest.appendChild(source.options[i].cloneNode( true ));发布于 2013-05-22 17:57:38
我发现这篇文章很有用:IE’s cloneNode doesn’t actually clone!
https://stackoverflow.com/questions/3654298
复制相似问题