javascript常见用法总结(2)


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>动态添加表格数据</title>

<script type="text/javascript">

var mailArr = [
{ "title": "一个c#问题", "name": "张三", "date": "2014-03-21" },
{ "title": "一个javascript问题", "name": "李四", "date": "2014-03-21" },
{ "title": "一个c问题", "name": "五五", "date": "2014-03-21" },
{ "title": "一个c++问题", "name": "赵六", "date": "2014-03-21" }
];

window.onload = function () {
var tab = document.getElementById("tb");
//把mailArr循环遍历方式以tr的方式加入表格中
for (var rowindex = 0; rowindex < mailArr.length; rowindex++) {
var tr = document.createElement("tr");
var th1 = document.createElement("th");
var th2 = document.createElement("th");
var th3 = document.createElement("th");
var th4 = document.createElement("th");
th1.innerHTML = "<input type='checkbox'/>";
th2.innerHTML = mailArr[rowindex].title;
th3.innerHTML = mailArr[rowindex].name;
th4.innerHTML = mailArr[rowindex].date;

tr.appendChild(th1);
tr.appendChild(th2);
tr.appendChild(th3);
tr.appendChild(th4);

tab.appendChild(tr);
}

};
</script>

</head>
<body>
<table>
<tr>
<th>序列</th>
<th>标题</th>
<th>发邮人</th>
<th>发件时间</th>
</tr>
<!-- 循环增加 -->
</table>
</body>
</html>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgpfdx.html