Html 动态创建表格


在项目中写到的一段代码:

在<table id="allPerson"></table> 节点下面循环创建表格

js 文件中

//接受参数为一个存储客户的数组,根据客户个数,创建相应个数的表格

function createCustomerElement(personObject) {
remove("allPerson");
var obj_length = 0;
if(personObject.length > 20){
obj_length = 20;
}else{
obj_length = personObject.length;
}
for(var i = 0; i < obj_length;i++){
   var tr = document.createElement('tr');
var td_username = document.createElement('td');
var td_cussex = document.createElement('td');
var td_birthday = document.createElement('td');
var td_operate = document.createElement('td');
var button1 = document.createElement('button');
   button1.setAttribute("uuid",personObject[i].id);
var button2 = document.createElement('button');
   button2.setAttribute("uuid",personObject[i].id);
var button3 = document.createElement('button');
   button3.setAttribute("uuid",personObject[i].id);
td_username.innerText = personObject[i].name;

   if(personObject[i].sex == "0"){
personObject[i].sex = "男";
}else if(personObject[i].sex == "1"){
personObject[i].sex = "女"; 
}
td_cussex.innerText = personObject[i].sex;
td_birthday.innerText = personObject[i].birthdate;
button1.className = "ico ico6 on";
        button2.className = "ico ico4 on";
        button3.className = "ico ico5 on";
button1.addEventListener('tap',function(){
var uuid = this.getAttribute("uuid");
var isSynLoading = plus.storage.getItem("isSynLoading");
    if(isSynLoading=="1"){
    alert("正在同步客户信息,请勿操作!");
    }else{
    detailinfos(uuid);        
    }
});
button2.addEventListener('tap',function(){
   var uuid = this.getAttribute("uuid");
   var isSynLoading = plus.storage.getItem("isSynLoading");
    if(isSynLoading=="1"){
    alert("正在同步客户信息,请勿操作!");
    }else{
    create(uuid);    
    }
});
button3.addEventListener('tap',function(){
uuid = this.getAttribute("uuid");
var isSynLoading = plus.storage.getItem("isSynLoading");
    if(isSynLoading=="1"){
    alert("正在同步客户信息,请勿操作!");
    }else{
    $('.masker,#deleteData').show();    
    }
});
       
td_operate.appendChild(button1);
td_operate.appendChild(button2);
td_operate.appendChild(button3);
tr.appendChild(td_username);
tr.appendChild(td_cussex);
tr.appendChild(td_birthday);
tr.appendChild(td_operate);
allPerson.appendChild(tr);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值