var rowIndex=0;
function AddOneLine_onclick()
{
var row=Table1.insertRow(Table1.rows.length);
var col=row.insertCell(0);
col.width="120";
col.innerHTML="<input name=code1"+rowIndex+" id=code1"+rowIndex+" style='width:100%' readonly onDblClick=\"addline(event.srcElement.id,'lh'),showCustomer('0',this.id)\">";
col=row.insertCell(1);
col.width="360";
col.innerHTML=" <input name=name1"+rowIndex+" id=name1"+rowIndex+" style='width:100%' readonly>";
col=row.insertCell(2);
col.width="80";
col.align="right";
col.innerHTML="<input type=text name=units"+rowIndex+" id=units"+rowIndex+" value=台 style='width:100%;text-align:right'>";
col=row.insertCell(3);
col.width="80";
col.align="right";
col.innerHTML="<input type=text name=num1"+rowIndex+" id=num1"+rowIndex+" style='width:100%;text-align:right' onChange=\"jsje("+rowIndex+")\">";
col=row.insertCell(4);
col.width="80";
col.align="right";
col.innerHTML="<input type=text name=price"+rowIndex+" id=price"+rowIndex+" style='width:100%;text-align:right' onChange=\"jsje("+rowIndex+")\">";
col=row.insertCell(5);
col.width="80";
col.align="right";
col.innerHTML="<input type=text name=total"+rowIndex+" id=total"+rowIndex+" style='width:100%;text-align:right'>";
col=row.insertCell(6);
col.width="100";
col.innerHTML="<INPUT type='button' value='增加' id=button0 name=button0 LANGUAGE=javascript onclick=\"return AddOneLine_onclick()\"><INPUT type='button' value='删除' id=button1 name=button1 LANGUAGE=javascript onclick=\"if(document.getElementById('outh').value>1){return Delete_Row('row"+rowIndex+"')}\">";
col.align="right" ;
row.setAttribute("id", "row"+rowIndex);
row.setAttribute("name","row"+rowIndex);
rowIndex++;
var htrow=Table1.rows.length;
document.getElementById("outh").value=htrow;
}
function jsje(hh)
{
var htrow=document.getElementById("outh").value
var num=document.getElementById("num1"+hh).value;
var price=document.getElementById("price"+hh).value;
var total=num*price;
document.getElementById("total"+hh).value=total;
var tote=0
for(hh=0;hh<htrow;hh++){
var x=Table1.rows[hh].id;
x=x.replace(/row/,"");
tote=Number(tote)+Number(document.getElementById("total"+x).value);}
document.getElementById("tote").value=tote;
} function Delete_Row(rowTag)
{
var i=Table1.rows(rowTag).rowIndex;
Table1.deleteRow(i);
document.getElementById("outh").value=rowIndex;
var tote=0;
for(hh=0;hh<i;hh++){
var x=Table1.rows[hh].id;
x=x.replace(/row/,"");
tote=Number(tote)+Number(document.getElementById("total"+x).value);}
document.getElementById("tote").value=tote;
}
在新增一行时,计算没有错误,但是删除一行的时候计算结果就变成0了,先谢谢大家了
function AddOneLine_onclick()
{
var row=Table1.insertRow(Table1.rows.length);
var col=row.insertCell(0);
col.width="120";
col.innerHTML="<input name=code1"+rowIndex+" id=code1"+rowIndex+" style='width:100%' readonly onDblClick=\"addline(event.srcElement.id,'lh'),showCustomer('0',this.id)\">";
col=row.insertCell(1);
col.width="360";
col.innerHTML=" <input name=name1"+rowIndex+" id=name1"+rowIndex+" style='width:100%' readonly>";
col=row.insertCell(2);
col.width="80";
col.align="right";
col.innerHTML="<input type=text name=units"+rowIndex+" id=units"+rowIndex+" value=台 style='width:100%;text-align:right'>";
col=row.insertCell(3);
col.width="80";
col.align="right";
col.innerHTML="<input type=text name=num1"+rowIndex+" id=num1"+rowIndex+" style='width:100%;text-align:right' onChange=\"jsje("+rowIndex+")\">";
col=row.insertCell(4);
col.width="80";
col.align="right";
col.innerHTML="<input type=text name=price"+rowIndex+" id=price"+rowIndex+" style='width:100%;text-align:right' onChange=\"jsje("+rowIndex+")\">";
col=row.insertCell(5);
col.width="80";
col.align="right";
col.innerHTML="<input type=text name=total"+rowIndex+" id=total"+rowIndex+" style='width:100%;text-align:right'>";
col=row.insertCell(6);
col.width="100";
col.innerHTML="<INPUT type='button' value='增加' id=button0 name=button0 LANGUAGE=javascript onclick=\"return AddOneLine_onclick()\"><INPUT type='button' value='删除' id=button1 name=button1 LANGUAGE=javascript onclick=\"if(document.getElementById('outh').value>1){return Delete_Row('row"+rowIndex+"')}\">";
col.align="right" ;
row.setAttribute("id", "row"+rowIndex);
row.setAttribute("name","row"+rowIndex);
rowIndex++;
var htrow=Table1.rows.length;
document.getElementById("outh").value=htrow;
}
function jsje(hh)
{
var htrow=document.getElementById("outh").value
var num=document.getElementById("num1"+hh).value;
var price=document.getElementById("price"+hh).value;
var total=num*price;
document.getElementById("total"+hh).value=total;
var tote=0
for(hh=0;hh<htrow;hh++){
var x=Table1.rows[hh].id;
x=x.replace(/row/,"");
tote=Number(tote)+Number(document.getElementById("total"+x).value);}
document.getElementById("tote").value=tote;
} function Delete_Row(rowTag)
{
var i=Table1.rows(rowTag).rowIndex;
Table1.deleteRow(i);
document.getElementById("outh").value=rowIndex;
var tote=0;
for(hh=0;hh<i;hh++){
var x=Table1.rows[hh].id;
x=x.replace(/row/,"");
tote=Number(tote)+Number(document.getElementById("total"+x).value);}
document.getElementById("tote").value=tote;
}
在新增一行时,计算没有错误,但是删除一行的时候计算结果就变成0了,先谢谢大家了
{
var i=Table1.rows(rowTag).rowIndex;
Table1.deleteRow(i);
document.getElementById("outh").value=rowIndex;
var tote=0;
for(hh=0;hh<i;hh++){
var x=Table1.rows[hh].id;
x=x.replace(/row/,"");
tote=Number(tote)+Number(document.getElementById("total"+x).value);}
document.getElementById("tote").value=tote;
}
分别把上面那些值数出来看看。。看看是哪里不正确