Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2014 16:35
Show Gist options
  • Save anonymous/10400178 to your computer and use it in GitHub Desktop.
Save anonymous/10400178 to your computer and use it in GitHub Desktop.
var heads = ['NAME', 'AGE', 'GENER'];
var rows = [['TOM', 21, 'MALE'],['LUCY', 16, 'FEMALE'],['JERRY', 23, 'MALE']];
// '<table><thead><tr>'+
// 在这里循环 head
// for head in heads:
// <th>head</th>
// '</tr></thead><tbody>'+
// 在这里循环 rows
// for row in rows:
// <tr>
// 这里循环 row 里面的单元格
// for cell in row:
// <td>cell</td>
// </tr>
// '</tbody></table>';
var html = '<table><thead><tr>';
for (var i = 0; i < heads.length; i++)
html += '<th>'+heads[i]+'</th>';
html += '</tr></thead><tbody>';
for (i = 0; i < rows.length; i++) {
html += '<tr>';
for (var j = 0; j < rows[i].length; j++)
html += '<td>'+ rows[i][j] +'</td>';
html += '</tr>';
}
html += '</tbody></table>';
console.log(html);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment