当前位置: 代码迷 >> PHP >> 请问js动态增加表格的每个字段为input,但是不能提交值
  详细解决方案

请问js动态增加表格的每个字段为input,但是不能提交值

热度:27   发布时间:2016-04-28 19:05:25.0
请教js动态增加表格的每个字段为input,但是不能提交值
一:动态增加行的js代码
var index;
index = 1;
function insertRow(){
var s1 = "<input type = 'text' style='width:100%' name = 'duty' />";
var s2 = "<input type = 'text' style='width:100%' name = 'place' />";
var s3 = "<input type = 'text' style='width:100%' name = 'ephone' />";
var s4 = "<input type = 'text' style='width:100%' name = 'sec' />";
var s5 = "<input type = 'text' style='width:100%' name = 'sphone' />";
var s6 = "<input type = 'text' style='width:100%' name = 'olset' />";
var s7 = "<input type = 'text' style='width:100%' name = 'olex' />";
var s8 = "<input type = 'text' style='width:100%' name = 'vpnex' />";
var s9 = "<input type = 'text' style='width:100%' name = 'tokenex' />";
var s10 = "<a href = javascript:delRow('"+index+ "')><img src='pic/49882.png' border='0' width='10' height='10' /></a>";

var table = document.getElementById('table1');
row = table.insertRow(index);
/*insertRow() 方法用于在表格中的指定位置插入一个新行。
语法tableObject.insertRow(index)
返回值    返回一个 TableRow,表示新插入的行。
说明
该方法创建一个新的 TableRow 对象,表示一个新的 <tr> 
标记,并把它插入表中的指定位置。
新行将被插入 index 所在行之前。若 index 
等于表中的行数,则新行将被附加到表的末尾。
如果表是空的,则新行将被插入到一个新的 <tbody> 段,该段自身会被插入表中。
  num = document.getElementById("tbl").rows.length;
  R = tbl.insertRow(num-2);      //倒数第2行插入
抛出
若参数 index 小于 0 或大于等于表中的行数,该方法将抛出代码为 INDEX_SIZE_ERR 的 DOMException 异常。*/
row.id = "tr" + index;
c1 = row.insertCell(-1);//插入列td,一个一个插入,代码用innerHTML写入
c1.innerHTML = s1;

c2 = row.insertCell(-1);
c2.innerHTML = s2;

c3 = row.insertCell(-1);
c3.innerHTML = s3;


c4 = row.insertCell(-1);
c4.innerHTML = s4;

c5 = row.insertCell(-1);
c5.innerHTML = s5;

c6 = row.insertCell(-1);
c6.innerHTML = s6;

c7 = row.insertCell(-1);
c7.innerHTML = s7;

c8 = row.insertCell(-1);
c8.innerHTML = s8;

c9 = row.insertCell(-1);
c9.innerHTML = s9;

c10 = row.insertCell(-1);
c10.innerHTML = s10;

}
function delRow(index){

var table = document.getElementById('table1');
table.deleteRow(document.getElementById("tr" + index).rowIndex);
this.index = this.index - 1;


二.FORM内容
<form action="proinsert.php" method="post">
<div id="header">
<div id="hl"></div>
<div id="hm">
成都VIP档案-<?php echo "$enname"?>
</div>
<div id="hr">
<input type="button"  onmouseover="this.className='on1' " onmouseout="this.className='out1'" style="width:80px; height:40px; font-size:12px; font-family:'Microsoft YaHei UI'; border:1px solid #CDCDCD;" onclick="javascript:history.back(-1);" value="返回上一页"><input type="button"  onmouseover="this.className='on1' " onmouseout="this.className='out1'" style="width:80px; height:40px; font-size:12px; font-family:'Microsoft YaHei UI'; border:1px solid #CDCDCD;" onclick="location.href=('vip.php')" value="返回主页">
</div>

</div>
<div id="line1"></div>
<div id="header">
<div id="header1">
<div id="inheader1">
帐号信息
</div>
<input type="button" id="b1" value="添加" onclick="insertRow()"  />
</div> 
<div id="header2">
<input  name="mysubmit" type="submit" value="提交"  onmouseover="this.className='on1' " onmouseout="this.className='out1'" style="width:80px; height:30px; font-size:14px; font-family:'Microsoft YaHei UI'; border:1px solid #CDCDCD;" />
</div>
</div>
<div id="m">
<table id="table1" align="center" width="1200px" border="0px" >
<th style="width:150px; color:#FF6666;" >职务</th>
<th style="color:#FF6666;">办公地点</th>
<th style="width:50px; color:#FF6666;">分机号</th>
<th style="width:50px; color:#FF6666;">秘书</th>
<th style="width:50px; color:#FF6666;">分机号</th>
<th style="color:#FF6666;">outlook修改时间</th>
<th style="color:#FF6666;">outlook有效期</th>
  相关解决方案