代码实现的功能是按回车键,插入列...现在需要求H列的和.求教.谢谢大家...<table id="table1" width='100%' border='1' cellpadding='0' cellspacing='0'>
<tr align='center' bgcolor='#E6E6E6'>
<td width='30' height='28' align="center" bgcolor='#E6E6E6'>序号</td>
<td width="100" bgcolor='#E6E6E6'>日期</td>
<td width="150" bgcolor='#E6E6E6'>A</td>
<td width="100" bgcolor='#E6E6E6'>B</td>
<td width="100" bgcolor='#E6E6E6'>C</td>
<td bgcolor='#E6E6E6'>D</td>
<td width="70" bgcolor='#E6E6E6'>E</td>
<td width="40" bgcolor='#E6E6E6'>F</td>
<td width="80" bgcolor='#E6E6E6'>G</td>
<td bgcolor='#E6E6E6'>H</td>
</tr>
<tr id='addtable' align='center' bgcolor='#FFFFFF'>
<td height="28">1</td>
<td><input class="inputbian" size="10" type="hidden">2011-3-24</td>
<td><input class="inputbian" style="width=140" size="18" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=100" size="12" onmouseover='this.focus()'></td>
<td><input style="width=100" class="inputbian" size="12" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=60" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=40" size="8" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=30" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<p>G列的和是:</p>
</body>
</html>
<script language="JavaScript">var i=1;
//设置行号
function Addrow(){ var newTR = addtable.cloneNode(true);
newTR.id="a"+(++i);
addtable.parentNode.insertAdjacentElement("beforeEnd",newTR);
newTR.children[0].innerHTML=i;
}
function Delrow(){
var num = table1.rows.length;
if(num==2) return;
table1.deleteRow(table1.rows[num-1].rowIndex);
i--;
}
function ShortcutKey(){
if(window.event.keyCode==8)
Delrow();
if(window.event.keyCode==13)
Addrow();
}
document.onkeydown=ShortcutKey;
</script>
<tr align='center' bgcolor='#E6E6E6'>
<td width='30' height='28' align="center" bgcolor='#E6E6E6'>序号</td>
<td width="100" bgcolor='#E6E6E6'>日期</td>
<td width="150" bgcolor='#E6E6E6'>A</td>
<td width="100" bgcolor='#E6E6E6'>B</td>
<td width="100" bgcolor='#E6E6E6'>C</td>
<td bgcolor='#E6E6E6'>D</td>
<td width="70" bgcolor='#E6E6E6'>E</td>
<td width="40" bgcolor='#E6E6E6'>F</td>
<td width="80" bgcolor='#E6E6E6'>G</td>
<td bgcolor='#E6E6E6'>H</td>
</tr>
<tr id='addtable' align='center' bgcolor='#FFFFFF'>
<td height="28">1</td>
<td><input class="inputbian" size="10" type="hidden">2011-3-24</td>
<td><input class="inputbian" style="width=140" size="18" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=100" size="12" onmouseover='this.focus()'></td>
<td><input style="width=100" class="inputbian" size="12" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=60" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=40" size="8" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=30" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<p>G列的和是:</p>
</body>
</html>
<script language="JavaScript">var i=1;
//设置行号
function Addrow(){ var newTR = addtable.cloneNode(true);
newTR.id="a"+(++i);
addtable.parentNode.insertAdjacentElement("beforeEnd",newTR);
newTR.children[0].innerHTML=i;
}
function Delrow(){
var num = table1.rows.length;
if(num==2) return;
table1.deleteRow(table1.rows[num-1].rowIndex);
i--;
}
function ShortcutKey(){
if(window.event.keyCode==8)
Delrow();
if(window.event.keyCode==13)
Addrow();
}
document.onkeydown=ShortcutKey;
</script>
<tr id='addtable' align='center' bgcolor='#FFFFFF'>
<td><input name=“textA” id=“textA” type="text" /></td>
<td><input name=“textH” id=“textH” type="text" /></td>
</tr>JS里
var text = document.getElementsByName("text" + H);
var value =0;
for(var i=0;i<text.length;i++){
value = value + text[i].value
}
当然 你也可以
var table = document.getElementById("table1");
然后用table.rows 控制行数 循环得到tr 同理可以得到tr下的第H个TD然后得到TD下的input对象 然后获取value 相加得出值上面都是思路 真正相加的时候要注意判断 加的对象值是数值型的不,还有遍历的时候是否有改行或者改列
<tr align='center' bgcolor='#E6E6E6'>
<td width='30' height='28' align="center" bgcolor='#E6E6E6'>序号</td>
<td width="100" bgcolor='#E6E6E6'>日期</td>
<td width="150" bgcolor='#E6E6E6'>A</td>
<td width="100" bgcolor='#E6E6E6'>B</td>
<td width="100" bgcolor='#E6E6E6'>C</td>
<td bgcolor='#E6E6E6'>D</td>
<td width="70" bgcolor='#E6E6E6'>E</td>
<td width="40" bgcolor='#E6E6E6'>F</td>
<td width="80" bgcolor='#E6E6E6'>G</td>
<td bgcolor='#E6E6E6'>H</td>
</tr>
<tr id='addtable' align='center' bgcolor='#FFFFFF'>
<td height="28">1</td>
<td><input class="inputbian" size="10" type="hidden">2011-3-24</td>
<td><input class="inputbian" style="width=140" size="18" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=100" size="12" onmouseover='this.focus()'></td>
<td><input style="width=100" class="inputbian" size="12" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=60" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=40" size="8" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=30" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<p>G列的和是:</p>
</body>
</html>
<script language="JavaScript">
HTMLElement.prototype.insertAdjacentElement =function(where,parsedNode){
switch(where){
case "beforeBegin":
this.parentNode.insertBefore(parsedNode,this);
break;
case "afterBegin":
this.insertBefore(parsedNode,this.firstChild);
break;
case "beforeEnd":
this.appendChild(parsedNode);
break;
case "afterEnd":
if(this.nextSibling)
this.parentNode.insertBefore(parsedNode,this.nextSibling);
else
this.parentNode.appendChild(parsedNode);
break;
}
}
var i=1;
//设置行号
function Addrow(){ var newTR = addtable.cloneNode(true);
newTR.id="a"+(++i);
addtable.parentNode.insertAdjacentElement("beforeEnd",newTR);
newTR.children[0].innerHTML=i;
}
function Delrow(){
var num = table1.rows.length;
if(num==2) return;
table1.deleteRow(table1.rows[num-1].rowIndex);
i--;
}
function ShortcutKey(e){
var ee=e||window.event;
if(ee.keyCode==8)
Delrow();
if(ee.keyCode==13)
Addrow();
}
document.onkeydown=ShortcutKey;
</script>楼主你指的求H列的和,然后在哪显示呢?要求和的意思是指把某行内的所有A—H列的所有列的数值加起来?
把求和的结果在表格下边显示即可.求和的计算方法是:一个表格一共有:A,B,C,......H这么多列.(H列是一定会有数据的)
假如现在插入了十行(现在这个代码的功能就是,每按一次回车.就在表格里插一行),每行都有数据.那么想得到的就是H1+H2.....+H10的结果(H后边的数字是行号)
<tr align='center' bgcolor='#E6E6E6'>
<td width='30' height='28' align="center" bgcolor='#E6E6E6'>序号</td>
<td width="100" bgcolor='#E6E6E6'>日期</td>
<td width="150" bgcolor='#E6E6E6'>A</td>
<td width="100" bgcolor='#E6E6E6'>B</td>
<td width="100" bgcolor='#E6E6E6'>C</td>
<td bgcolor='#E6E6E6'>D</td>
<td width="70" bgcolor='#E6E6E6'>E</td>
<td width="40" bgcolor='#E6E6E6'>F</td>
<td width="80" bgcolor='#E6E6E6'>G</td>
<td bgcolor='#E6E6E6'>H</td>
</tr>
<tr id='addtable' align='center' bgcolor='#FFFFFF'>
<td height="28">1</td>
<td><input class="inputbian" size="10" type="hidden">2011-3-24</td>
<td><input class="inputbian" style="width=140" size="18" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=100" size="12" onmouseover='this.focus()'></td>
<td><input style="width=100" class="inputbian" size="12" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=60" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=40" size="8" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=30" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<p>G列的和是:</p>
</body>
</html>
<script language="JavaScript">
var i=1;
//设置行号
function Addrow(){ var newTR = addtable.cloneNode(true);
newTR.id="a"+(++i);
if(!(/msie/i.test(navigator.userAgent)))
{addtable.parentNode.appendChild(newTR);}
else
{addtable.parentNode.insertAdjacentElement("beforeEnd",newTR);}
newTR.children[0].innerHTML=i;
}
function Delrow(){
var num = table1.rows.length;
if(num==2) return;
table1.deleteRow(table1.rows[num-1].rowIndex);
i--;
}
function ShortcutKey(e){
var ee=e||window.event;
if(ee.keyCode==8)
Delrow();
if(ee.keyCode==13)
Addrow();
}
document.onkeydown=ShortcutKey;
</script>
还是说:H列实际就是统计A到G列的所有值的和,然后表格外需要再统计一下H1到H10的总和,??是这个意思吗
<tr align='center' bgcolor='#E6E6E6'>
<td width='30' height='28' align="center" bgcolor='#E6E6E6'>序号</td>
<td width="100" bgcolor='#E6E6E6'>日期</td>
<td width="150" bgcolor='#E6E6E6'>A</td>
<td width="100" bgcolor='#E6E6E6'>B</td>
<td width="100" bgcolor='#E6E6E6'>C</td>
<td bgcolor='#E6E6E6'>D</td>
<td width="70" bgcolor='#E6E6E6'>E</td>
<td width="40" bgcolor='#E6E6E6'>F</td>
<td width="80" bgcolor='#E6E6E6'>G</td>
<td bgcolor='#E6E6E6'>H</td>
</tr>
<tr id='addtable' align='center' bgcolor='#FFFFFF'>
<td height="28">1</td>
<td><input class="inputbian" size="10" type="hidden">2011-3-24</td>
<td><input class="inputbian" style="width=140" size="18" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=100" size="12" onmouseover='this.focus()'></td>
<td><input style="width=100" class="inputbian" size="12" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=60" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=40" size="8" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=30" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<p>H列的和是:<span id="kk"></span></p>
</body>
</html>
<script language="JavaScript">var i=1;
//设置行号
function $(id){return document.getElementById(id)}
function GetSum(){
var sum=0,num;
if ($("addtable")){
num = $("addtable").getElementsByTagName("input")[8].value;
if (!isNaN(num)){
sum+=-(0-num);
}
}
for (var j=2;j<=i;j++){
if ($("a"+j)){
num = $("a"+j).getElementsByTagName("input")[8].value; if (!isNaN(num)){
sum+=-(0-num);
}
}
}
$("kk").innerText = sum;
}function Addrow(){ var newTR = addtable.cloneNode(true);
newTR.id="a"+(++i); addtable.parentNode.insertAdjacentElement("beforeEnd",newTR);
newTR.children[0].innerHTML=i;
}
function Delrow(){
var num = table1.rows.length;
if(num==2) return;
table1.deleteRow(table1.rows[num-1].rowIndex);
i--;
}
function ShortcutKey(){
if(window.event.keyCode==8)
Delrow();
if(window.event.keyCode==13)
Addrow();
}
document.onkeydown=ShortcutKey;
document.onkeyup=GetSum;;
</script>
<tr align='center' bgcolor='#E6E6E6'>
<td width='30' height='28' align="center" bgcolor='#E6E6E6'>序号</td>
<td width="100" bgcolor='#E6E6E6'>日期</td>
<td width="150" bgcolor='#E6E6E6'>A</td>
<td width="100" bgcolor='#E6E6E6'>B</td>
<td width="100" bgcolor='#E6E6E6'>C</td>
<td bgcolor='#E6E6E6'>D</td>
<td width="70" bgcolor='#E6E6E6'>E</td>
<td width="40" bgcolor='#E6E6E6'>F</td>
<td width="80" bgcolor='#E6E6E6'>G</td>
<td bgcolor='#E6E6E6'>H</td>
</tr>
<tr id='addtable' align='center' bgcolor='#FFFFFF'>
<td height="28">1</td>
<td><input class="inputbian" size="10" type="hidden">2011-3-24</td>
<td><input class="inputbian" style="width=140" size="18" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=100" size="12" onmouseover='this.focus()'></td>
<td><input style="width=100" class="inputbian" size="12" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=60" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=40" size="8" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=30" size="5" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" onmouseover='this.focus()'></td>
<td><input class="inputbian" style="width=70" size="10" value=8 onmouseover='this.focus()'></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<p>H列的和是:<span id="pp"></span></p>
</body>
</html>
<script language="JavaScript">
var i=1;
//设置行号
function sum(){
var first=document.getElementById("addtable").getElementsByTagName("input")[8].value;
var ss=0;
for(var j=2;j<i+1;j++)
{
var input=document.getElementById("a"+j).getElementsByTagName("input");
ss+=parseInt(input[8].value);
}
document.getElementById("pp").innerHTML=ss+parseInt(first);
}function Addrow(){
var newTR = addtable.cloneNode(true);
newTR.id="a"+(++i);
addtable.parentNode.appendChild(newTR);
newTR.children[0].innerHTML=i;
}
function Delrow(){
if(addtable.parentNode.children[2])
{addtable.parentNode.removeChild(addtable.parentNode.lastChild);}
}
function ShortcutKey(e){
var ee=e||window.event;
if(ee.keyCode==8)
Delrow();
if(ee.keyCode==13)
Addrow();
sum();
}
document.onkeydown=ShortcutKey;
</script>