用js怎麼動態插入行!

來源:互聯網
上載者:User
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>


相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。