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);
}
}
在<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);
}
}
相关文章推荐
- 手机版html中用input模拟select...
- HTML::Entities 编码或解码 HTML 实体的字符串
- HTML::Entities 编码或解码 HTML 实体的字符串
- HTML中label标签的作用
- 正则表达式替换html元素属性
- <html>a
- html的meta总结
- html续
- HTML解析原理
- 01-html
- HTML知识点笔记(持续添加+++++++)
- WebBasic01-HTML
- HTML--百度百科
- Uncaught SyntaxError: Failed to set the 'innerHTML' property on 'Element'
- emmet使用(HTML)
- 淡蓝风格的手机登录HTML模板
- HTML简单使用
- HTML简单使用
- HTML简单使用
- HTML——4(超链接)