(谢谢各位,重新开贴发问)从数字一到数字五相加得到结果,给与数字六.代码如下.怎么不行?
<table id= "tb1 " name= "tb1 " border=1>
<tr> <td> 开头一 </td> <td> 开头二 </td> <td> 开头三 </td> <td> 开头四 </td> <td> 数字一 </td> <td> 数字二 </td> <td> 数字三
</td> <td> 数字四 </td> <td> 数字五 </td> <td> 数字六(总和) </td> </tr>
<tr>
<td> 开头一 </td>
<td> 开头二 </td>
<td> 开头三 </td>
<td> 开头四 </td>
<td> <input type= "text "> </td>
<td> <input type= "text "> </td>
<td> <input type= "text "> </td>
<td> <input type= "text "> </td>
<td> <input type= "text "> </td>
<td> <input type= "text "> </td>
</tr>
<tr>
<td> 开头一 </td>
<td> 开头二 </td>
<td> 开头三 </td>
<td> 开头四 </td>
<td> <input type= "text "> </td>
<td> <input type= "text "> </td>
<td> <input type= "text "> </td>
<td> <input type= "text "> </td>
<td> <input type= "text "> </td>
<td> <input type= "text "> </td>
</tr>
</table>
<script type= "text/javascript ">
var table = document.getElementById( "tb1 ");
for(var i=1;i <table.rows.length;i++){
var row = table.rows[i];
row.cells[10].firstChild.readOnly= "true ";
row.cells[5].firstChild.onchange=row.cells[6].firstChild.onchange=row.cells
[7].firstChild.onchange=row.cells[8].firstChild.onchange=row.cells[9].firstChild.onchangefunction(){
row.cells[10].firstChild.value=row.cells[5].firstChild.value*1 + row.cells
[6].firstChild.value*1 + row.cells[7].firstChild.value*1 + row.cells[8].firstChild.value*1 + row.cells
[9].firstChild.value*1
}
}
</script>
------解决方案--------------------.....
------解决方案--------------------cell从0开始算,按照你的TABLE应该是从4开始
------解决方案--------------------sorry,我的错,原来的代码只适用于1行,现在可以了
------------------------------------------------------
<script type= "text/javascript ">
var table = document.getElementById( "tb1 ");
for(var i=1;i <table.rows.length;i++){
var row = table.rows[i];
row.cells[9].firstChild.readOnly= "true ";
row.cells[4].firstChild.onchange=row.cells[5].firstChild.onchange=row.cells[6].firstChild.onchange=row.cells[7].firstChild.onchange=row.cells[8].firstChild.onchange=function(){
var crow = this.parentElement.parentElement;
crow.cells[9].firstChild.value=crow.cells[4].firstChild.value*1 + crow.cells[5].firstChild.value*1 + crow.cells[6].firstChild.value*1 + crow.cells[7].firstChild.value*1 + crow.cells[8].firstChild.value*1;
}
}
</script>
------解决方案-------------------- <table id= "tb1 " name= "tb1 " border=1>
<tr> <td> 开头一 </td> &l