0
我想在兩個div之間移動一些元素。一切正常與onclick事件,但是當我swicth到addEventListener它讓我切換幾次元素。addEventListener無法正常工作
這裏是previev http://jsfiddle.net/2u6nyxp4/1/。
有人可以解釋這是爲什麼嗎?謝謝。
HTML
<div id="one">
<span>One</span>
<span>Two</span>
</div>
<div id="two"><span>One</span></div>
JAVASCRIPT
var one = document.getElementById('one');
var two = document.getElementById('two');
var movetoOne = function() {
one.appendChild(this);
bindEvents (this,movetoTwo);
}
var movetoTwo = function() {
two.appendChild(this);
bindEvents (this,movetoOne);
}
var bindEvents = function (childList, moveEvent) {
childList.onclick = moveEvent;
}
for (i=0; i < one.children.length ; i+=1) {
bindEvents(one.children[i], movetoTwo);
}
for (i=0; i < two.children.length ; i+=1) {
bindEvents(two.children[i], movetoOne);
}