JavaScript DOM操作例表
1386 ワード
HTML:
<!DOCTYPE html>
<html>
<head>
<title>JS createTable</title>
</head>
<body>
</body>
<script>
var myBody = document.getElementsByTagName("body")[0];
var myTable = document.createElement("table");
myTable.border = "1";
for(var j=0;j<2;j++)
{
myTr = document.createElement("tr");
for(var i = 0;i<4;i++)
{
myTd = document.createElement("td");
myTr.appendChild(myTd);
}
myTable.appendChild(myTr);
}
myBody.appendChild(myTable);
TD = document.getElementsByTagName("td");
innerText0_0 = document.createTextNode(" ");
TD[0].appendChild(innerText0_0);
innerText0_1 = document.createTextNode(" ");
TD[1].appendChild(innerText0_1);
innerText0_2 = document.createTextNode(" ");
TD[2].appendChild(innerText0_2);
innerText0_3 = document.createTextNode(" ");
TD[3].appendChild(innerText0_3);
innerText1_0 = document.createTextNode(" ");
TD[4].appendChild(innerText1_0);
innerText1_1 = document.createTextNode(" ");
TD[5].appendChild(innerText1_1);
innerText1_2 = document.createTextNode(" ");
TD[6].appendChild(innerText1_2);
innerText1_3 = document.createTextNode(" ");
TD[7].appendChild(innerText1_3);
</script>
</html>