表格插入行与删除行示例

java代码
<html>
<head>
<title>表格插入行与删除行示例</title>

<script type="text/javascript">
//参数列表[表格id,复制行的索引,标题行数,表单id]
function clickinsert(inputtable,rowid,titlerow,inputform){
var oform=document.getelementbyid(inputform);
var otable=document.getelementbyid(inputtable);
var obj =window.event.srcelement;
var otd = obj.parentelement;
var otr = otd.parentelement;
var orow = otr.rowindex;
var otr1 = otable.insertrow(orow+1);
var ocells = otr.cells;
for(i=0;i<ocells.length;i++){
var cell = ocells[i].innerhtml;
var cell1 = otr1.insertcell(i);
cell1.innerhtml=cell;
}
oform.flag[orow+1-titlerow].value="1";
//alert(oform.flag[orow+1-titlerow].value="1");
}


//参数列表[表格id,标题行数,表单id]
function clickdelete(inputtable,titlerow,inputform){
var oform=document.getelementbyid(inputform);
var otable=document.getelementbyid(inputtable);
var obj =window.event.srcelement;
var otd = obj.parentelement;
var otr = otd.parentelement;
var orow = otr.rowindex;
otr.style.display="none";
oform.flag[orow-titlerow].value="2";
// alert(oform.flag[orow-titlerow].value);
}

function submitform(){
var flags= inputform.flag;
for(i=0;i<flags.length;i++){
alert(flags[i].value);
}
}
</script>
</head>
<body>
<form action="" name="inputform" id="inputform">
<table id="inputtable" width="50%" align="center" border="1" cellpadding="0"
cellspacing="0">
<tr>
<td>
学生
</td>
<td>
课程
</td>
<td>
&nbsp;
</td>
<td>
&nbsp;
</td>
</tr>
<tr style="display: none;">
<td>
<input type="hidden" name="flag" id="flag" value="-1" />
<select id="studentid">
<option value="01">
张三
</option>
<option value="02">
李四
</option>
</select>
</td>
<td>
<select id="courseid">
<option value="01">
英语
</option>
<option value="02">
数学
</option>
</select>
</td>
<td>
<input type="button" name="insertbutton" value="新增" />
</td>
<td>
<input type="button" name="deletebutton" value="删除" />
</td>
</tr>
<tr>
<td>
<input type="hidden" name="flag" id="flag" value="1" />
<select id="studentid">
<option value="01">
张三
</option>
<option value="02">
李四
</option>
</select>
</td>
<td>
<select id="courseid">
<option value="01">
英语
</option>
<option value="02">
数学
</option>
</select>
</td>
<td>
<input type="button" name="insertbutton" value="新增"
onclick="clickinsert('inputtable',1,1,'inputform')" />
</td>
<td>
<input type="button" name="deletebutton" value="删除"
onclick="clickdelete('inputtable',1,'inputform')" />
</td>
</tr>
</table>
<br />
<center><input type="button" name="submitbutton" value="提交" onclick="submitform()" /></center>
</form>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值