用js怎么动态插入行!

80酷酷网    80kuku.com

  js|插入|动态<script language="JavaScript">
//构造函数
function InsterCell(tableId,content,place){
this.mTableId=tableId;//table的标识
this.mInsContent=content;//inster的内容
this.mInsPlace=place;//inster的位置

this.cInsCell=InsCell;
this.cClearCell=ClearCell;

}
//插入
function InsCell(){
str=eval(this.mTableId+".cells["+this.mInsPlace+"]");//这个这样写也不行!
str.innerHTML='<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" ><tr>';
this.mTableId.cells[this.mInsPlace].innerHTML=this.mInsContent;

this.mTableId.cells[this.mInsPlace].innerHTML='</tr></table>';
this.mInsPlace++;
}
//清楚
function ClearCell(){
for(i=0;i<this.mTableId.cells.length/2-1;i++){
this.mTableId.cells[2*i+1].innerHTML="";
}
}
str='<TD>交行原余额</TD>';
str+='<TD><input type="text" name="earning"></TD>';
str+='<TD><input type="text" name="payout"></TD>';
str+='<TD><input type="text" name="cashOnHand"> </TD>';
str+='<TD><input type="text" name="cashOnHandRemark"></TD>';

var ins=new InsterCell("t1","str",1);
ins.cInsCell();

</script>

代码:--------------------------------------------------------------------------------
<html>
<head>
<title>发货单</title>
</head>
<body bgcolor="#F2FDE8" text="000000" link="000000" vlink="000000" alink="000000">

<SCRIPT language="javascript">

function tbladdrow()
{
var i=lines.rows.length;
var row = Table1.insertRow(Table1.rows.length);
var col = row.insertCell(0);
col.innerHTML = "<INPUT id=line["+i+"][Commcd] name=line["+i+"][Commcd]>";
col = row.insertCell(1);
col.innerHTML = "<INPUT id=line["+i+"][SerialNo] name=line["+i+"][SerialNo]>";
col = row.insertCell(2);
col.innerHTML = "<INPUT id=line["+i+"][Qty] name=line["+i+"][Qty]>";
}
function tbladdrows(items)
{
for( i = 1 ; i <= items ; i++)
{
tbladdrow();
}
}
function delrow()
{
if(lines.rows.length==0)
{
return false;
}
lines.deleteRow();
}

</SCRIPT>

<CENTER>
<P><H1 class=title>发货单</H1></P>
<FORM action="testlines.php" method=post id=Form1 name=Form1>
<!-- LANGUAGE=javascript onsubmit="return checkNumArray('Qty')" -->
<P>订货单位:演示零售商
日期:2002-02-25
订单号:
<INPUT id=items name=items value=1>
<INPUT id=corpcd name=corpcd type=hidden value=26>
<INPUT id=eventid name=eventid type=hidden value=2266>
<INPUT id=addrow name=addrow type=button value=加一行 onclick="tbladdrows(items.value);">
<INPUT id=DelOneLine name=DelOneLine type=button value=删一行 LANGUAGE=javascript onclick="return delrow()">
</P>
<TABLE id=Table1 border="1" cellpadding="4" cellspacing="0" bordercolorlight="#006830" bordercolordark="#FFFFFF" width="60%">
<TR bgcolor="#E1F0C4">
<TH>货号</TH>
<TH>生产批号</TH>
<TH>数量</TH>
</TR>
<tbody id="lines" name="lines">
<!--
<tr>
<td><INPUT id=Commcd name=Commcd value=JC002></td>
<td><INPUT id=SerialNo name=SerialNo value=9911></td>
<td><INPUT id=Qty name=Qty value=0.0></td>
</tr>
-->
</tbody>
<!--
</TABLE>
<H2 class=title>库存列表</H2>
<TABLE border="1" cellpadding="4" cellspacing="0" bordercolorlight="#006830" bordercolordark="#FFFFFF" width="60%">
<TR bgcolor="#E1F0C4">
<TH>货号</TH>
<TH>生产批号</TH>
<TH>库存数量</TH>
</TR>

</TABLE>-->
<P>

<INPUT id=commit name=commit type=submit value=提交>

</P>
</FORM>
</CENTER>
</body>
</html>



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: