首页 > 开发 > PHP > 正文

用js怎么动态插入行!

2024-05-04 22:54:40
字体:
来源:转载
供稿:网友
<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>

最大的网站源码资源下载站,

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表