表格上移、下移、添加、删除函数
function moveUp(_a){
var _row = _a.parentNode.parentNode;
var _node = _row.previousSibling;
while(_node && _node.nodeType != 1){
_node = _node.previousSibling;
}
if(_node){
swapNode(_row,_node);
}
}
function moveDown(_a){
var _row = _a.parentNode.parentNode;
var _node = _row.nextSibling;
while(_node && _node.nodeType != 1){
_node = _node.nextSibling;
}
if(_node){
swapNode(_row,_node);
}
}
function swapNode(node1,node2){
var val1=node1.firstChild.lastChild.value;
var val2=node2.firstChild.lastChild.value;
node1.firstChild.lastChild.value=val2;
node2.firstChild.lastChild.value=val1;
var _parent = node1.parentNode;
var _t1 = node1.nextSibling;
var _t2 = node2.nextSibling;
if(_t1)_parent.insertBefore(node2,_t1);
else _parent.appendChild(node2);
if(_t2)_parent.insertBefore(node1,_t2);
else _parent.appendChild(node1);
}
function del(obj) {
obj.parentNode.parentNode.remove()
}
function show(element) {
var oldhtml = element.innerHTML;
if (oldhtml == null || oldhtml.length == 0) {
return alert("不能为空!");
}
var newInput = document.createElement('input');
newInput.type = 'text';
newInput.value = oldhtml;
newInput.onblur = function() {
element.innerHTML = this.value == oldhtml ? oldhtml : this.value;
}
element.innerHTML = '';
element.appendChild(newInput);
newInput.setSelectionRange(0, oldhtml.length);
newInput.focus();
}
function addTableRow() {
var table1 = document.getElementById('xxnr');
var cloneTab = document.getElementById('xxnr');
table1.firstChild.appendChild(cloneTab.firstChild.firstChild.cloneNode(true));
var v= table1.firstChild.childNodes;
var len = v.length;
for(var i=1;i<len;i++){
v[i].childNodes[0].firstChild.id=i;
}
}