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

jsp菜鸟求问各位大神为什么我这个创建表格不能循环
<html>
<head>
<title>this is my first web</title>
</head>
<script language="javascript">
function st()
{
for(var j = 0; j < 3; j++) 
{
var x=document.getElementById("myTable").insertRow(1+j)
var y=x.insertCell(0+j);
var z=x.insertCell(1+j);
  y.innerHTML="NEWcell";
  z.innerHTML="sdfs";
}
}
</script>
<body background="one.jpg" color="red">
<form>
<input type="button" id="start_button" value="start" onclick="st()" >
<table id="myTable" border="1" width=250>
<tr>
<td>Chinses</td>
<td>Japanese</td>
</tr>
</table>
<br />
</form>
</body>
</html>

------解决方案--------------------
有脚本错误:Index or size is negative or greater than the allowed amount
 function st() {
for (var j = 0; j < 3; j++) {
var x = document.getElementById("myTable").insertRow(1 + j)
var y = x.insertCell(0);
var z = x.insertCell(1);
y.innerHTML = "NEWcell";
z.innerHTML = "sdfs";
}
}
这样就可以了