您的位置:首页 > Web前端 > HTML

Html 动态创建表格

2016-04-28 10:58 369 查看
在项目中写到的一段代码:

在<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);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: