下面的页面只有两个<tr>可以填写数据,我要实现的效果是如果数量不够,就利用添加项添加新的<tr>.这个添加项用js来实现,谁做过啊,指教下
页面代码
<form id="user">
<table class="TBboder">
<tr class="dvDeptTitle">
<td class="tTitle">
<center><h:outputLabel for="txtDept" value="交接人签名" /></center>
</td>
<td >
<center><h:outputLabel for="txtDept" value="部门重要通知" /></center>
</td>
<td class="tTitle">
<center><h:outputLabel for="txtDept" value="接收人签名" /></center>
</td>
</tr>
<tr >
<td class="tTitle">
<input id="transferSignature" msg="必填" />
</td>
<td >
<input id="content" msg="必填" />
</td>
<td class="tTitle">
<input id="receverSignature" msg="必填" />
</td>
</tr>
<tr >
<td class="tTitle">
<input id="showname" msg="必填" />
</td>
<td >
<input id="showname" msg="必填" />
</td>
<td class="tTitle">
<input id="showname" msg="必填" />
</td>
</tr>
</table>
</form>
页面代码
<form id="user">
<table class="TBboder">
<tr class="dvDeptTitle">
<td class="tTitle">
<center><h:outputLabel for="txtDept" value="交接人签名" /></center>
</td>
<td >
<center><h:outputLabel for="txtDept" value="部门重要通知" /></center>
</td>
<td class="tTitle">
<center><h:outputLabel for="txtDept" value="接收人签名" /></center>
</td>
</tr>
<tr >
<td class="tTitle">
<input id="transferSignature" msg="必填" />
</td>
<td >
<input id="content" msg="必填" />
</td>
<td class="tTitle">
<input id="receverSignature" msg="必填" />
</td>
</tr>
<tr >
<td class="tTitle">
<input id="showname" msg="必填" />
</td>
<td >
<input id="showname" msg="必填" />
</td>
<td class="tTitle">
<input id="showname" msg="必填" />
</td>
</tr>
</table>
</form>
var tb1=document.getElementById(tableid);
var newRow=tb1.insertRow(tb1.rows.length-1);
$("#"+tableid+" tr:last").find("td").each(function (i){
newRow.insertCell(i).innerHTML=$(this).html();
});
}
//获取tableid
var tb1=document.getElementById(tableid);
//为tableid添加一行
var newRow=tb1.insertRow(tb1.rows.length-1); //为此行添加列(自动复制你表格的最后一行)
$("#"+tableid+" tr:last").find("td").each(function (i){ //当i等于0的时候就是复制你表格的最后一行的第1个td
//当i等于1的时候就是复制你表格的最后一行的第2个td
......
newRow.insertCell(i).innerHTML=$(this).html();
});
}
var newRow=tb1.insertRow(tb1.rows.length-1);
这段代码报错了,执行到这里就不往下执行了
<script type="text/javascript" language="javascript">function addRow(tableid){
var tb1=document.getElementById(sprcialevent);
var newRow = tb1.insertRow(tb1.rows.length+1);
$("#"+tableid+" tr:last").find("td").each(function (i){
newRow.insertCell(i).innerHTML=$(this).html();
});
}</script>