日期:2014-05-16  浏览次数:20397 次

js 控制表格
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>

<!--表单元素名可以用行数做后缀,后台取值的时候可以把隐藏域的值取出来,用他循环取到所有表单元素的值,你也可以用相同的表单名,后台会取到数组?没试过-->
<form>

<script language="JavaScript">
function addRow(obj)
{
var num = document.all.logger.value;
document.all.logger.value=(document.all.logger.value*1)+1;
//添加一行
var newTr = membertable.insertRow();
//增加列
var newTd0 = newTr.insertCell();
var newTd1 = newTr.insertCell();
var newTd2 = newTr.insertCell();
var newTd3 = newTr.insertCell();
var newTd4 = newTr.insertCell();
var newTd5 = newTr.insertCell();
var newTd6 = newTr.insertCell();
var newTd7 = newTr.insertCell();
var newTd8 = newTr.insertCell();

//设置列内容和属性

//注意里面表单元素的名字,我这里没做修改,自己改成自己想要的吧
newTd0.innerHTML = (num*1+1);
newTd1.innerHTML= "<input type='text' size='8' name='PROD_NM"+(num*1)+"' />";
newTd2.innerHTML= "<input type='text' size='8' name='PROD_MODEL_CH"+(num*1)+"' />";
newTd3.innerHTML= "<input type='text' size='8' name='PROD_MODEL_CH"+(num*1)+"' />";
newTd4.innerHTML= "<input type='text' size='8' name='PROD_MODEL_CH"+(num*1)+"' />";
newTd5.innerHTML= "<input type='text' size='8' name='PROD_MODEL_CH"+(num*1)+"' />";
newTd6.innerHTML= "<input type='text' size='8' name='PROD_MODEL_CH"+(num*1)+"' />";
newTd7.innerHTML= "<input type='text' size='8' name='PROD_MODEL_CH"+(num*1)+"' />";
newTd8.innerHTML= "<input name='button' type='button' onclick='__javascript:delRow(this.parentElement.parentElement)' value='删除' />";
newTd0.align = "center";
newTd1.align = "center";
newTd2.align = "center";
newTd3.align = "center";
newTd4.align = "center";
newTd5.align = "center";
newTd6.align = "center";
newTd7.align = "center";
newTd8.align = "center";
}
function   delRow(src){
src.parentElement.deleteRow(src.rowIndex);

}
</script>
<input type="button" onclick="addRow() " value="增加一行"><input type="hidden" id='logger' name="logger" value="2"><!--这里的隐藏域的值等于一开始的行数(不包括标题行,如现在就等于2)--><br>

<table width='100%' id="membertable" border='1' cellpadding='1' cellspacing='0'>
    <tr>
      <td colspan='9' align='center'>成员组成方案</td>
    </tr>
    <tr>
      <td align='center'>序号</td>
      <td align='center'>本会职务</td>
      <td align='center'>姓名</td>
      <td align='center'>工作单位</td>
      <td align='center'>职务/职称</td>
      <td align='center'>电话</td>
      <td align='center'>Email</td>
      <td align='center'>备注</td>
    
      <td align='center'>删除</td>
    </tr>
   
      <tr>
        <td align='center'>1</td>
        <td align='center'><input type='text' size='8' name='PROD_NM0' /></td>
        <td align='center'&