js添加行

<div>     
        <input type="button" name="Submit" value="添加" οnclick="AddSignRow()" />
        <!-- <input type="button" name="Submit2" value="清空"
            οnclick="ClearAllSign()" />  -->
            <input name='txtTRLastIndex'
            type='hidden' id='txtTRLastIndex' value="1" />
    </div>
    <table class="tableStyle" transMode="true" footer="normal"
        id="SignFrame">
        <tr>
            <th width="25%">序号</th>
            <th width="25%">衣服类型</th>
            <th width="25%">数量(件)</th>
            <th>删除</th>
        </tr>

    </table>


js为:

function changeValue(para,paraT){
    var realvalue=document.getElementById(para+paraT).value;
    document.getElementById(para+"T"+paraT).value=escape(realvalue);
}
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文本框中
     debugger;
     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 = newTR.rowIndex.toString();
     
     //添加列: 姓名
     var newNameTD=newTR.insertCell(1);
     //添加列内容
     newNameTD.innerHTML = "<input  id='keyword" + rowID + "' type='text' οnchange='changeValue(\"keyword\","+rowID+")' style='width:100%;height:100%;' />"+
             "<input name='keyword' id='keywordT" + rowID + "'  type='hidden' " +
             " style='width:100%;height:100%;' />";
   
     
     //添加列:电子邮箱
     var newEmailTD=newTR.insertCell(2);
     //添加列内容
     newEmailTD.innerHTML = "<input  id='keyword" + rowID + "' type='text' οnchange='changeValue(\"keyword\","+rowID+")' style='width:100%;height:100%;' />"+
             "<input name='keyword' id='keywordT" + rowID + "'  type='hidden' " +
             " style='width:100%;height:100%;' />";
                     "οnchange='document.getElementById(\"keyword"+rowID+"\").value=this.value' style='width:100%;height:100%;' />";
     //添加列:删除按钮
     var newDeleteTD=newTR.insertCell(3);
     //添加列内容
     newDeleteTD.innerHTML = "<div align='center' style='width:40px'><a href='javascript:;' οnclick=\"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 addFirst(){//开始增加一行
         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();
    
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值