<%...@ 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>