添加tr
方法(1):
function insertUnit(){
var obj = window.showModalDialog("common/UserChooseMain.jsp",null,"dialogHeight:570px;dialogWidth:700px;status:off");
for(var i=0 ;i<obj.length;i++){
var confUnitList = document.getElementById("confUnitList");
size = confUnitList.rows.length;
var j=parseInt(size)-2;
var newRow = confUnitList.insertRow();
var cell0 = newRow.insertCell();
cell0.innerHTML = parseInt(size)-1;
var cell1 = newRow.insertCell();
cell1.innerHTML = '<input type="checkbox" name="unitcheckbox"><input type="hidden" name="requestConfUnitList['+j+'].requestConfUnitId">';
var cell2 = newRow.insertCell();
cell2.innerHTML = '<input type="hidden" name="requestConfUnitList['+j+'].unitId" value="'+obj[i].unitId+'"><input type="text" style="width:100%" name="requestConfUnitList['+j+'].unitName" value="'+obj[i].unitName+'" readonly="readonly">';
var cell3 = newRow.insertCell();
cell3.innerHTML = '<input type="hidden" name="requestConfUnitList['+j+'].depId" value="'+obj[i].depId+'"><input type="text" style="width:100%" name="requestConfUnitList['+j+'].depName" value="'+obj[i].deptName+'" readonly="readonly">';
var cell4 = newRow.insertCell();
cell4.innerHTML = '<input type="hidden" name="requestConfUnitList['+j+'].receiveId" value="'+obj[i].userId+'"><input type="text" style="width:100%" name="requestConfUnitList['+j+'].receiveName" value="'+obj[i].userName+'" readonly="readonly">';
}
}
方法(2):
function createtr(id,name){
var s= document.all.mainTable.rows.length
var tr = document.createElement('TR');
var td1 = document.createElement('TD');
td1.align = 'center';
td1.innerHTML=s;
tr.appendChild(td1);
var td2 = document.createElement('TD');
td2.align = 'center';
td2.innerHTML='<input type="hidden" name="assetsId" value="'+id+'">'+name;
tr.appendChild(td2);
var td3 = document.createElement('TD');
var provider = document.createElement('input');
td3.align = 'center';
td3.innerHTML='<input type="hidden" name="providerId" value="1">'+'<input type="text" class="textfield" name="providerName" value="">'+'<input type="button" class="bt_com6" value="选择供应商">';
tr.appendChild(td3);
var td4 = document.createElement('TD');
td4.align = 'center';
td4.innerHTML='<input type="text" name="memo" value="" class="textfield" size="32">'
tr.appendChild(td4);
var td5 = document.createElement('TD');
var buts = document.createElement('input');
td5.align = 'center';
td5.innerHTML='<input type="button" class="bt_com2" name="delete" value="删除" οnclick="deleteEquipment()" >'
tr.appendChild(td5);
mainTable.appendChild(tr);
}
方法(3):
function createRecord(id,name){
var s= document.all.mainTable.rows.length
var tr = document.createElement('TR');
var td1 = document.createElement('TD');
td1.align = 'center';
td1.innerHTML=s;
tr.appendChild(td1);
var td2 = document.createElement('TD');
var h_assetsId = document.createElement('input');
h_assetsId.type='hidden';
h_assetsId.value=id;
h_assetsId.name='assetsId';
td2.align = 'center';
td2.innerHTML='<input type="hidden" name="assetsId" value="'+id+'">'+name;
td2.appendChild(h_assetsId);
tr.appendChild(td2);
var td3 = document.createElement('TD');
var provider = document.createElement('input');
td3.align = 'center';
provider.size='30';
provider.readOnly=true;
provider.type='text';
provider.className='textfield';
provider.name='providerName'
var but=document.createElement('button');
but.className='bt_com4';
but.value='选择单位';
var h_providerId=document.createElement("input");
h_providerId.type='hidden';
h_providerId.name='providerId';
h_providerId.value=1;
td3.appendChild(h_providerId);
td3.appendChild(provider);
td3.appendChild(but);
tr.appendChild(td3);
var td4 = document.createElement('TD');
var memo = document.createElement('input');
td4.align = 'center';
memo.size='30';
memo.type='text';
memo.className='textfield';
memo.name='memo';
td4.appendChild(memo);
tr.appendChild(td4);
var td5 = document.createElement('TD');
var buts = document.createElement('input');
td5.align = 'center';
//buts.οnclick=deleteEquipment;
buts.type='button';
buts.className='bt_com2';
buts.value='删除';
td5.appendChild(buts) ;
tr.appendChild(td5);
mainTable.appendChild(tr);
alert(mainTable.innerHTML);
}