有没有比这更好的动态创建信息字段集的方法:
var grid = document.createElement("ul");
grid.style['text-align'] = "left";
// Creates the legend and append it
var child = document.createElement('legend');
child.innerHTML = "Logado - Dados";
loginbox.appendChild(child);
// End of creating the legend
// Start creating the first child
var cell = document.createElement("li");
cell.style['padding'] = "0px";
child = document.createElement('label');
child.innerHTML = "<b>Usuário: </b>";
child.for = "lusername";
cell.appendChild(child);
child = document.createElement('label');
child.innerHTML = response['username'];
child.for = "username";
cell.appendChild(child);
grid.appendChild(cell);
// End adding the first labels
// Start adding the second label
cell = document.createElement("li");
cell.style['padding'] = "0px";
child = document.createElement('label');
child.innerHTML = "<b>Membro Desde: </b>";
child.for = "lbirthday";
cell.appendChild(child);
child = document.createElement('label');
child.innerHTML = response['MemberSince'];
child.for = "birthday";
cell.appendChild(child);
grid.appendChild(cell);
// End adding the second labels
// Start adding the third label
cell = document.createElement("li");
cell.style['padding'] = "0px";
child = document.createElement('label');
child.innerHTML = "<b>Última Visita: </b>";
child.for = "llastvisit";
cell.appendChild(child);
child = document.createElement('label');
child.innerHTML = response['LastVisit'];
child.for = "lastvisit";
cell.appendChild(child);
grid.appendChild(cell);
// End adding the third labels
// Start adding the forth label
cell = document.createElement("li");
cell.style['padding'] = "0px";
child = document.createElement('label');
child.innerHTML = "<b>Frequência de Estudo: </b>";
child.for = "lstudyfrequency";
cell.appendChild(child);
child = document.createElement('label');
child.innerHTML = response['StudyFrequency'];
child.for = "studyfrequency";
cell.appendChild(child);
grid.appendChild(cell);
// End adding the forth labels
// Start adding the fifth label
cell = document.createElement("li");
cell.style['padding'] = "0px";
child = document.createElement('label');
child.innerHTML = "<b>Faculdade: </b>";
child.for = "lcollege";
cell.appendChild(child);
child = document.createElement('label');
child.innerHTML = response['College'];
child.for = "college";
cell.appendChild(child);
grid.appendChild(cell);
// End adding the fifth labels
// Start adding the sixth label
cell = document.createElement("li");
cell.style['padding'] = "0px";
child = document.createElement('label');
child.innerHTML = "<b>Curso: </b>";
child.for = "lcourse";
cell.appendChild(child);
child = document.createElement('label');
child.innerHTML = response['Course'];
child.for = "course";
cell.appendChild(child);
grid.appendChild(cell);
// End adding the sixth labels
loginbox.appendChild(grid);
我认为尝试以某种方式使用“写入”方法会更好。抱歉,我是 javascript 新手。