var linkEl = createElement('a');
linkEl.href = '#';
linkEl.onclick = this.upRow;
linkEl.setAttribute('columnId', k);
var innerEls = table.tBodies[0].rows[j+1].cells[k].childNodes;
linkEl.innerText = "上移";
table.tBodies[0].rows[j+1].cells[k].appendChild(linkEl);
var p = createElement('span');
p.innerHTML = " ";
table.tBodies[0].rows[j+1].cells[k].appendChild(p);
var linkEl2 = createElement('a');
linkEl2.href = '#';
linkEl2.onclick = this.downRow;
linkEl2.setAttribute('columnId', k);
var innerEls2 = table.tBodies[0].rows[j+1].cells[k].childNodes;
linkEl2.innerText = "下移";
table.tBodies[0].rows[j+1].cells[k].appendChild(linkEl2);
}
}
}
// 隔行换颜色,依赖odd样式
this.isOdd = true;
var rows = table.tBodies[0].rows;
// We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
for (var i=0;i<rows.length-1;i++) ...{
this.doStripe(rows[i+1]);
}
},
/**//**
* 隔行分色策略,依赖odd样式
**/
doStripe : function(rowItem) ...{
if (!this.isOdd) ...{
css.addClassToElement(rowItem, 'odd');
} else ...{
css.removeClassFromElement(rowItem, 'odd');
}
this.isOdd = !this.isOdd;
},
/**//**
* 删除目标列
**/
delRow : function(e) ...{
var that = crudbtn.that;
var linkEl = getEventTarget(e);
var td = linkEl.parentNode;
var tr = td.parentNode;
var thead = tr.parentNode;
var table = thead.parentNode;
if (!table.tBodies || table.tBodies[0].rows.length <= 1) ...{
return false;
}
this.isOdd = true;
var rows = table.tBodies[0].rows;
// 实现AJAX调用处理删除
var pars = "pars=";
for(h=0;h<tr.cells.length;h++) ...{
if(!css.elementHasClass(tr.cells[h],'editbtn')&&!css.elementHasClass(tr.cells[h],'delbtn')
&&!css.elementHasClass(tr.cells[h],'updownbtn')) ...{
var colid = tr.cells[h].getAttribute('columnId');
if(tr.cells[h].firstChild.value!=null) ...{
pars += h +"^"+ tr.cells[h].firstChild.value +"|";
}
else ...{
pars += h +"^"+ tr.cells[h].innerText +"|";
}
}
}
pars += "&command=delrow&callback=afterUpdate&table="+table.id;
table.deleteRow(tr.rowIndex);
// 重新隔行换色
for (var i=1;i<rows.length;i++) ...{
if (!this.isOdd) ...{
css.addClassToElement(rows[i], 'odd');
} else ...{
css.removeClassFromElement(rows[i], 'odd');
}
this.isOdd = !this.isOdd;
}
new Ajax.Updater('result','Dispatcher.ajax?'+pars,...{evalScripts: true});
if(table.rows.length<=1) ...{
alert("该页已无数据,系统将重载数据项");
window.location = "?";
}
},
/**//**
* 修改按钮
**/
editRow : function(e) ...{
var that = crudbtn.that;
var linkEl = getEventTarget(e);
var td = linkEl.parentNode;
var tr = td.parentNode;
var thead = tr.parentNode;
var table = thead.parentNode;
var column = linkEl.getAttribute('columnId') || td.cellIndex;
var cellcount = tr.cells.length;
// 如果没点击修改
if(tr.getAttribute('editing')!=1) ...{
for(var o=0;o<cellcount;o++) ...{
// 如果该列含有修改样式、删除样式或其他类似样式,则忽略该列
if(!css.elementHasClass(tr.cells[o],'editbtn')&&!css.elementHasClass(tr.cells[o],'delbtn')
&&!css.elementHasClass(tr.cells[o],'updownbtn') &&!css.elementHasClass(tr.cells[o],'noedit')) ...{
var inputEl = createElement('input');
inputEl.type = "text";
// 文本框大小
// inputEl.size = tr.cells[o].innerText.length*2; inputEl.size = tr.cells[o].innerText.replace(/[^\x00-\xff]/gi,'xx').length;
tr.cells[o].setAttribute('columnId', o);
inputEl.setAttribute('oldValue', tr.cells[o].innerHTML);
var inputEls = tr.cells[o].innerText;
inputEl.value = inputEls;
tr.cells[o].firstChild.removeNode(true);
tr.cells[o].appendChild(inputEl);
tr.setAttribute('editing',1);
linkEl.setAttribute('oldValue',linkEl.innerText);
}
}
linkEl.innerText = "确定";
var p = createElement('span');
p.innerHTML = " ";
td.appendChild(p);
var linkEl2 = createElement('a');
linkEl2.href="#";
linkEl2.onclick = that.cancelRow;
linkEl2.innerText = "取消";
td.appendChild(linkEl2);
}
用.Net实现基于CSS的AJAX开发(3)
80酷酷网 80kuku.com