上面说的很可能也只是猜测,刚才测试了下,这个方法就是深克隆的方法,晕死了
测试代码如下,我在想是不是因为克隆后的the已经包含了startFlying方法,而下面又复制了一个,浏览器不知道调哪个方法呢?报的错误是否为“找不到对象”呢?
<body onload=Load()>
<div id="div1" onclick="alert('haha')" style="background-color:red">
天外水火
</div><script>
function Load()
{
var the=( div1.cloneNode( true ) )
document.body.appendChild(the)
var objs=document.getElementsByTagName("div")
for(var i=0;i<objs.length;i++)
{
objs[i].click()
}
}
</script>
测试代码如下,我在想是不是因为克隆后的the已经包含了startFlying方法,而下面又复制了一个,浏览器不知道调哪个方法呢?报的错误是否为“找不到对象”呢?
<body onload=Load()>
<div id="div1" onclick="alert('haha')" style="background-color:red">
天外水火
</div><script>
function Load()
{
var the=( div1.cloneNode( true ) )
document.body.appendChild(the)
var objs=document.getElementsByTagName("div")
for(var i=0;i<objs.length;i++)
{
objs[i].click()
}
}
</script>
<body onload=Load()>
<div id="div1" onclick="alert('hbhbhbhbhb1021DIV1')" style="background-color:red">
天外水火div1
</div>
<div id="div2" onclick="alert('hbhbhbhbhb1021DIV2')" style="background-color:red">
天外水火div2
</div>
<script>
function Load()
{
var the=( div1.cloneNode( true ) )
document.body.appendChild(the)
var objs=document.getElementsByTagName("div")
objs[2].mergeAttributes(objs[1],true)
objs[2].click();
}
</script>
恐怕出在startFlying这个方法了
通过cloneNode复制出来的东西连id都是一样的,这样违背了id唯一原则,使用某些方法感觉有可能出些乱七八糟的问题
可这和直接写的区别并不大呀.
楼上的朋友,你的感觉实在太对了.var the=( flyingHigh.cloneNode( true ) )
并且
flyingHigh4.appendChild( the )
之后,DOM里就有了两个ID为flyingHigh的对象.而the.mergeAttributes( flyingHigh , true )实现上是the.mergeAttributes( document.all.flyingHigh , true )的简写,我加了一句the.id = "flyingHigh5",就好了.多谢多谢!