[zt]通过按钮添加行

[zt]通过按钮添加行
< html >
    
< head >
        
< script  language ="javascript" >
            
var  rowIndex  =   0 ;
            
            
function  addOneLineOnClick() {
                
var  row  =  tb.insertRow(tb.rows.length);
                col 
=  row.insertCell( 0 );
                col.innerHTML 
=   " <tr><input size='90'  name=btn index=\ "" + rowIndex + " \ "  > " ;
                col 
=  row.insertCell( 1 );
                col.innerHTML 
=   " <input type='button' value='Del'  onclick=\ " return  DeleteRow('row "  + rowIndex + " ')\ " ></tr> " ;
                row.setAttribute(
" id " " row "   +  rowIndex);
                row.setAttribute(
" name " " row "   +  rowIndex);
                rowIndex
++ ;
            }

            
function  DeleteRow(rowTag){
                
var  i  =  tb.rows(rowTag).rowIndex;
                
var  j;
                
for (j = i;j <= rowIndex;j ++ ) { 
                    tb.rows(j).cells(
0 ).all( " btn " ).index --
                }
                tb.deleteRow(i);
                rowIndex
-- ;
            }
        
</ script >
    
</ head >
    
< body  >
        
< div  align ="center" >             
            
< table  width ="95%"  name ="tb"  id ="tb" >
                
< tr >
                
</ tr >
            
</ table >
            
< p >             
            
< input  name ="btnAddLine"  type ="button"  id ="btnAddLine"  onClick ="return addOneLineOnClick()"  value ="Add" >
        
</ div >
    
</ body >
</ html >

你可能感兴趣的:([zt]通过按钮添加行)