<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script type="text/javascript">
function a(){
var otable=document.getElementById("tab");
var atext=[],otr=[],otd=[];
for(var i=0;i<5;i++){
atext[i]=(Math.random()+"").substr(0,3);
otr[i]=otable.insertRow();
for(var j=0;j<5;j++){
otd[j]=otr[i].insertCell();
otd[j].appendChild(atext[i].cloneNode(true));
}
}
}
</script>
<body onload="a()">
<table id="tab">
</table>
</body>
</html>

解决方案 »

  1.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <script type="text/javascript">
    function a(){
    var otable=document.getElementById("tab");
    var atext=[],otr=[],otd=[];
    for(var i=0;i<5;i++){
    atext[i]=document.createElement("textarea");
    atext[i].innerHTML=(Math.random()+"").substr(0,3);
    otr[i]=otable.insertRow(i);
    for(var j=0;j<5;j++){
    otd[j]=otr[i].insertCell(j);
    otd[j].appendChild(atext[i].cloneNode(true));
    }
    }
    }
    </script>
    <body onload="a()">
    <table id="tab">
    </table>
    </body>
    </html>
    不知是不是你想要的
      

  2.   

    知道错在哪里了,是错在innerHTML只能用在元素节点而不能用atext.innerHTML文本节点