<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>JSON FOR 迴圈</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<table class="for-table" border="1">
<thead>
<tr>
<th>姓名</th>
<th>出生日期</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script type="text/JavaScript">
var json = [{"name": "李四", "birthday": "1981-02-05"},
{"name": "三豐", "birthday": "1999-06-15"}];
var forTable = $(".for-table tbody");
var jsonSum = json.length;
for (var i = 0; i < jsonSum; i++) {
forTable.append(
"<tr>" +
"<td>" + json[i].name + "</td>" +
"<td>" + json[i].birthday + "</td>" +
"</tr>");
}
</script>
</body>
</html>
留言列表