元素位置交换成功后,事件丢失了,怎么办?var currtRow = document.getElementById(LevelArr[0]).parentNode;
var exRow = currtRow.nextSibling;
var currtCell = currtRow.childNodes[1];/////这个元素在交换位置之前已经绑定了事件
var exCell = exRow.childNodes[0]; /////这个元素在交换位置之前已经绑定了事件TableClass.prototype.exchange =function(obj){
var $o = {
Row:null,
Cell:null,
ExRow:null,
ExCell:null
}
Object.extend($o,obj,true);
var $Cell = $o.ExCell.cloneNode(true);
var $ExCell = $o.Cell.cloneNode(true);
$o.Row.removeChild($o.Cell);
$o.Row.appendChild($Cell);//添加克隆元素
$o.ExRow.removeChild($o.ExCell);
$o.ExRow.appendChild($ExCell);//添加克隆元素
}
var exRow = currtRow.nextSibling;
var currtCell = currtRow.childNodes[1];/////这个元素在交换位置之前已经绑定了事件
var exCell = exRow.childNodes[0]; /////这个元素在交换位置之前已经绑定了事件TableClass.prototype.exchange =function(obj){
var $o = {
Row:null,
Cell:null,
ExRow:null,
ExCell:null
}
Object.extend($o,obj,true);
var $Cell = $o.ExCell.cloneNode(true);
var $ExCell = $o.Cell.cloneNode(true);
$o.Row.removeChild($o.Cell);
$o.Row.appendChild($Cell);//添加克隆元素
$o.ExRow.removeChild($o.ExCell);
$o.ExRow.appendChild($ExCell);//添加克隆元素
}
用cloneNode复制容器,但cloneNode在ie中有一个bug:
在ie用attachEvent给dom元素绑定事件,在cloneNode之后会把事件也复制过去。
而用addEventListener添加的事件就不会