2010-04-22 45 views
3

我遇到了一个控制问题,我正在构建一个包含正文可滚动表格的表格。该行有一个点击()函数处理程序建立,如:jQuery通过点击()处理程序添加一行到tr

/** 
    * This function is called when the user clicks the mouse on a row in 
    * our scrolling table. 
    */ 
    $('.innerTable tr').click (function (e) { 
     // 
     // Only react to the click if the mouse was clicked in the DIV or 
     // the TD. 
     // 
     if (event.target.nodeName == 'DIV' || 
      event.target.nodeName == 'TD' ) { 
     // 
     // If the user wasn't holding down the control key, then deselect 
     // any previously selected columns. 
     // 
     if (e.ctrlKey == false) { 
      $('.innerTable tr').removeClass ('selected'); 
     } 

     // 
     // Toggle the selected state of the row that was clicked. 
     // 
     $(this).toggleClass ('selected'); 
     } 
    }); 

有一个按钮,增加了行表所示:当行被成功添加,出于某种原因

$('#innerTable > tbody:last').append('<tr>...some information...</tr>'); 

中,静态行与点击处理程序一起工作,但新添加的行不会。有什么我失踪?

回答

3

尝试使用.live()

$('.innerTable tr').live('click', function (e) { ... }); 

它将事件处理程序绑定到任何当前和未来元件选择匹配添加到DOM。

+0

我爱你:)。非常感谢你! – Dave 2010-04-22 01:13:36

相关问题