<%...@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>無標題頁</title>
<script>...
function onload()
...{
var k=document.getElementById("div1");
var t=document.createElement("p");
t.appendChild(document.createTextNode("This is a new paragraph with "));
k.appendChild(t);
}
function onload1()
...{
var k=document.getElementById("div1");
var t1=document.createElement("tbody");//用tr來appendChild(td),然後再用tbody來appendChild(tr),然後再用table來appendChild(tbody)就動態產生了一個table了。
var t=document.createElement("table");
var tr=document.createElement("tr");
var td=document.createElement("td");
td.appendChild(document.createTextNode("This is a new colum of zhe table!"));
tr.appendChild(td);
t1.appendChild(tr);
t.appendChild(t1);
k.appendChild(t);
alert(t.innerHTML);//innerHTML是用來顯示內部標籤。
}
</script>
</head>
<body onload="onload1()">
<form id="form1" runat="server">
<div id="div1">
</div>
</form>
</body>
</html>