javascript的innerhtml使用请教

2024-12-29 20:09:14
推荐回答(2个)
回答1:

var ct3 = {
i:1,
addRow:function(event_ff, type, data){
var table =document.getElementById("testTbl");
if(type == 'down'){
var obj = (document.all)?event.srcElement:event_ff;
var index= obj.parentNode.parentNode.rowIndex;
index++;
}else if(type == 'up') {
var obj = (document.all)?event.srcElement:event_ff;
var index= obj.parentNode.parentNode.rowIndex;
}else{
index = table.rows.length;
}
var newTr =table.insertRow(index);
if(data==0){
var newTd = newTr.insertCell(0);
newTd.style.background = '#ffffff';
newTd.innerHTML = '';
newTd = newTr.insertCell(1);
newTd.style.background = '#ffffff';
newTd.innerHTML = '';
}else{
var tmp_id = data['carinfo']['mid'];
var newTd = newTr.insertCell(0);
newTd.style.background = '#ffffff';
newTd.innerHTML = '';
newTd = newTr.insertCell(1);
newTd.style.background = '#ffffff';
newTd.innerHTML = '';
}
newTd = newTr.insertCell(2);
newTd.style.background = '#ffffff';
newTd.innerHTML = '';
newTd = newTr.insertCell(3);
newTd.style.background = '#ffffff';
newTd.innerHTML = '';
newTd = newTr.insertCell(4);
newTd.style.background = '#ffffff';
newTd.innerHTML = '';
newTd = newTr.insertCell(5);
newTd.style.background = '#ffffff';
newTd.innerHTML = ' ';
this.i++;
},
removeCurrentRow:function(event_ff) {
var table =document.getElementById("testTbl");
var obj = (document.all)?event.srcElement:event_ff;
var index= obj.parentNode.parentNode.rowIndex;
table.deleteRow(index);
}
}

---------------------------------------------------
调用参考下面的









-------------------------------------------
你可以参考下以上代码

回答2:

function addtr(){
var tb = document.getElementById("tdata");
var tr = document.getElementById("tr1");
var newTr = tr.innerHTML;
tb.appendChild(newTr);
}