动态添加和删除行

None.gif < html >
None.gif    
< head >
None.gif        
< title > 动态添加和删除行 </ title >
ExpandedBlockStart.gifContractedBlock.gif        
< script  type ="text/javascript" > dot.gif
InBlock.gif            
<!--
InBlock.gif            
var count = 1;
InBlock.gif            
var nRows = 2;
InBlock.gif            
ExpandedSubBlockStart.gifContractedSubBlock.gif            
function addRow() dot.gif{
InBlock.gif                
InBlock.gif                 
var tBody = document.getElementById('theBody');
InBlock.gif                 
var newRow = document.createElement('tr');
InBlock.gif                 
var col1 = document.createElement('td');
InBlock.gif                 
var col2 = document.createElement('td');
InBlock.gif                 
var col3 = document.createElement('td');
InBlock.gif                 
var rA = document.createElement('a');
InBlock.gif
InBlock.gif                 newRow.setAttribute('id', 'n' 
+ count);
InBlock.gif                
InBlock.gif             rA.setAttribute('href', 'javascript:removeRow(\'n' 
+ count + '\');');
InBlock.gif                 rA.appendChild(document.createTextNode('Remove'));
InBlock.gif                    
InBlock.gif              col1.appendChild(document.createTextNode('Col 
1 Row ' + nRows));
InBlock.gif              col2.appendChild(document.createTextNode('Col 
2 Row ' + nRows));
InBlock.gif                col3.appendChild(rA);
InBlock.gif
InBlock.gif                newRow.appendChild(col1);
InBlock.gif                newRow.appendChild(col2);
InBlock.gif                newRow.appendChild(col3);
InBlock.gif
InBlock.gif                tBody.appendChild(newRow);
InBlock.gif
InBlock.gif                count
++;
InBlock.gif                nRows
++;
InBlock.gif    
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
function removeRow(rowId) dot.gif{
InBlock.gif                 
var tBody = document.getElementById('theBody');
InBlock.gif                 tBody.removeChild(document.getElementById(rowId));
InBlock.gif                nRows
--;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
-->
ExpandedBlockEnd.gif        
</ script >
None.gif    
</ head >
None.gif    
< body >
None.gif        
< table >
None.gif            
< tbody  id ="theBody" >
None.gif            
< tr >
None.gif                 
< td > Col 1 Row 1 </ td >
None.gif                 
< td > Col 2 Row 1 </ td >
None.gif              
</ tr >                  
None.gif            
</ tbody >
None.gif        
</ table >     
None.gif        
< p >< href ="javascript:addRow()" > Add Row </ a ></ p >
None.gif    
</ body >
None.gif
</ html >

转载于:https://www.cnblogs.com/applegreen/archive/2005/07/01/184613.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值