<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>增加Table行</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
-->
</style>
</head>
<script language="javascript">// Example: obj = findObj("image1");
function findObj(theObj, theDoc){  
var p, i, foundObj;
    if(!theDoc) theDoc = document; 
if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) {
theDoc = parent.frames[theObj.substring(p+1)].document;
theObj = theObj.substring(0,p);  }
if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
for (i=0; !foundObj && i < theDoc.forms.length; i++)
foundObj = theDoc.forms[i][theObj]; 
for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
foundObj = findObj(theObj,theDoc.layers[i].document);
if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj); 
return foundObj;
}
//添加一个参与人填写行
function AddSignRow(){ //读取最后一行的行号,存放在txtTRLastIndex文本框中 
 var txtTRLastIndex = findObj("txtTRLastIndex",document);
 var rowID = parseInt(txtTRLastIndex.value);
 
 var signFrame = findObj("SignFrame",document);
 //添加行
 var newTR = signFrame.insertRow(signFrame.rows.length);
 newTR.id = "SignItem" + rowID;
 
 //添加列:序号
 var newNameTD=newTR.insertCell(0);
 //添加列内容
 newNameTD.innerHTML = "<font style='color:red;text-align:center;'>"+newTR.rowIndex.toString()+"</font>";
 
 var product_ItemName=newTR.insertCell(1);
 //newEmailTD.innerHTML = "<input name='txtEMail" + rowID + "' id='txtEmail" + rowID + "' type='text' size='10' />";
 product_ItemName.innerHTML="<select name='product_ItemName"+rowID+"' id='product_ItemName"+rowID+"' style='width:100px;'><option value='限时抢购'>限时抢购</option><option value='推广产品'>推广产品</option><option value='产品展示'>产品展示</option><option value='拍卖'>拍卖</option></select>"
 
 var product_name=newTR.insertCell(2);
 product_name.innerHTML = "<input name='product_name" + rowID + "' id='product_name" + rowID + "' type='text' size='10' />";
 
 var product_brank=newTR.insertCell(3);
 product_brank.innerHTML = "<input name='product_brank" + rowID + "' id='product_brank" + rowID + "' type='text' size='10' />";
 
 var product_itemNumber=newTR.insertCell(4);
 product_itemNumber.innerHTML = "<input name='product_itemNumber" + rowID + "' id='product_itemNumber" + rowID + "' type='text' size='10' />";
 
 var product_price=newTR.insertCell(5);
 product_price.innerHTML = "<input name='product_price" + rowID + "' id='product_price" + rowID + "' type='text' size='10' />";
 
 var product_shoppingPrice=newTR.insertCell(6);
 product_shoppingPrice.innerHTML = "<input name='product_shoppingPrice" + rowID + "' id='product_shoppingPrice" + rowID + "' type='text' size='10' />";
 
 var productShoppingDay=newTR.insertCell(7);
 productShoppingDay.innerHTML = "<input name='productShoppingDay" + rowID + "' id='productShoppingDay" + rowID + "' type='text' size='10' />";
 
 var product_color=newTR.insertCell(8);
 product_color.innerHTML = "<input name='product_color" + rowID + "' id='product_color" + rowID + "' type='text' size='10' />";
 
 var product_size=newTR.insertCell(9);
 product_size.innerHTML = "<input name='product_size" + rowID + "' id='product_size" + rowID + "' type='text' size='10' />";
 
 var product_number=newTR.insertCell(10);
 product_number.innerHTML = "<input name='product_number" + rowID + "' id='product_number" + rowID + "' type='text' size='10' />";
 
 var newCompanyTD=newTR.insertCell(11);
 newCompanyTD.innerHTML = "<input name='txtCompany" + rowID + "' id='txtCompany" + rowID + "' type='text' size='10' />";
 
 var yaomaideProduct=newTR.insertCell(12);
 yaomaideProduct.innerHTML = "<input name='yaomaideProduct" + rowID + "' id='yaomaideProduct" + rowID + "' type='text' size='10' />";
 
 var productAff_price=newTR.insertCell(13);
 productAff_price.innerHTML = "<input name='productAff_price" + rowID + "' id='productAff_price" + rowID + "' type='text' size='10' />";
 
  var productAff_price=newTR.insertCell(14);
 productAff_price.innerHTML = "<input name='productAff_price" + rowID + "' id='productAff_price" + rowID + "' type='text' size='10' />";
 
 var newDeleteTD=newTR.insertCell(15);
 newDeleteTD.innerHTML = "<div align='center' style='width:40px;font-size:12px;'><a href='javascript:;' onclick=\"DeleteSignRow('SignItem" + rowID + "')\">删除</a></div>";
 
 //将行号推进下一行
 txtTRLastIndex.value = (rowID + 1).toString() ;
}
//删除指定行
function DeleteSignRow(rowid){
 var signFrame = findObj("SignFrame",document);
 var signItem = findObj(rowid,document);
 
 //获取将要删除的行的Index
 var rowIndex = signItem.rowIndex;
 
 //删除指定Index的行
 signFrame.deleteRow(rowIndex);
 
 //重新排列序号,如果没有序号,这一步省略
 for(i=rowIndex;i<signFrame.rows.length;i++){
  signFrame.rows[i].cells[0].innerHTML = i.toString();
 }
}//清空列表
function ClearAllSign(){
 if(confirm('确定要清空所有参与人吗?')){
  var signFrame = findObj("SignFrame",document);
  var rowscount = signFrame.rows.length;
  //循环删除行,从最后一行往前删除
  for(i=rowscount - 1;i > 0; i--){
   signFrame.deleteRow(i);
  }
  //重置最后行号为1
  var txtTRLastIndex = findObj("txtTRLastIndex",document);
  txtTRLastIndex.value = "1";
  
  //预添加一行
  AddSignRow();
 }
}
//获取数据保存 
function subTable(){
var signFrame = findObj("SignFrame",document);
  var rowscounts = signFrame.rows;
  for(var i=1;i<rowscounts.length;i++){
  alert(i+":rowscounts");
alert(i.cells.length+":=2")
  }
}
</script>
<body onLoad="AddSignRow()">
<div>
  <table width="0" border="0" cellpadding="2" cellspacing="1" id="SignFrame">
    <tr id="trHeader">
      <td width="30" align="center" bgcolor="#96E0E2"><span class="STYLE1">序号</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品所属</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品名称</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品品牌</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品货号</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品单价</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品抢购价</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">活动截至</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品颜色</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品尺码</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品数量</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品图片</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">要卖的商品</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">要卖的商品价格</span></td>
      <td width="80" align="center" bgcolor="#96E0E2"><span class="STYLE1">商品图片</span></td>
      <td width="57" align="center" bgcolor="#96E0E2"><span class="STYLE1">操作</span></td>
    </tr>
  </table>
</div>
<div>
  <input type="button" name="Submit" value="添加" onClick="AddSignRow()" />
  <input type="button" name="Submit2" value="清空" onClick="ClearAllSign()" />
  <input type="button" name="" value="提交" onClick="subTable();" />
  <input name='txtTRLastIndex' type='hidden' id='txtTRLastIndex' value="1" />
</div>
</body>
</html>