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

下面的javascpipt代码为何不执行?
不知道错在哪
<TABLE id="table1" border=1 width="150">
<TR>
<TD align="center" width="50%">0,0</TD>
<TD align="center">0,1</TD>
</TR>
<TR>
<TD align="center">1,0</TD>
<TD align="center">1,1</TD>
</TR>
</TABLE>
<form name="form1" method="post" action="">
输入要添加的文字:<br><input type="text" name="f1"><br>
行<input type="text" size="5" name="row" value="0">&nbsp;
列<input type="text" size="5" name="col" value="0"><br>
<input type="button" value="添加" onclick="f2()">
</form>
<script>  
function f2()
{
col=parseInt(document.form1.col.value);  
row=parseInt(document.form1.row.value);
f1=document.form1.f1.value;
document.getElementById("table1").rows.item(row).cells.item(col).innerHTML=f1;
}
</script>

------解决方案--------------------
分开写吧:

<TABLE id="table1" border=1 width="150">
<TR>
<TD align="center" width="50%">0,0</TD>
<TD align="center">0,1</TD>
</TR>
<TR>
<TD align="center">1,0</TD>
<TD align="center">1,1</TD>
</TR>
</TABLE>
<form name="form1" method="post" action="">
输入要添加的文字:<br><input type="text" name="f1"><br>
行<input type="text" size="5" name="row" value="0">&nbsp;
列<input type="text" size="5" name="col" value="0"><br>
<input type="button" value="添加" onclick="f2()">
</form>
<script>  
function f2()
{
col=parseInt(document.form1.col.value);  
row=parseInt(document.form1.row.value);
f1=document.form1.f1.value;
//document.getElementById("table1").rows.item(row).cells.item(col).innerHTML=f1;
table = document.getElementById("table1")
for(var i=1;i<=row;i++){
 drow = table.insertRow(table.rows.length);
 for(var j=1;j<=col;j++){
  drow.insertCell(drow.cells.length).innerHTML=f1;
 }
}
}
</script>

------解决方案--------------------
引用:
Quote: 引用:

楼主说说在哪个浏览器里面出现的问题
ie,360都试过了,不行,换了不是ie内核的火狐也不行
我测试啦都可以,注意啊这里的第一行第一格是0,0啊