日期:2014-05-16  浏览次数:20428 次

这段代码错在哪里,应该怎么改?
<!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>

------解决方案--------------------
<!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>
不知是不是你想要的