2012-07-30 23 views
0

我有一个表,看起来像这样的TR内:从锚定一个让TR可点击使用jQuery

<table id=reportTbl> 
    <tbody> 
    <tr> 
     <td> 
     <table id=list> 
      <tbody> 
      <tr> 
       <td> 
       <a title="View Report" onclick="viewReport(123);"><img src="../images/report/icon_pdf.gif" border="0"></a> 
       </td> 
       <td>Customer Orders</td> 
       <td>USA</td> 
       <td>Jul 20 2012 3:32PM</td> 
      </tr> 
      ..... 

      </tbody> 
     </table> 
     </td> 
    </tr> 
    </tbody> 
</table> 

我想要在#list表整个表行点击。我想加入

$('#reportTbl #list a').each(function() { 
    // I have other code in this section 
    // .... 
    // end other section  

    $(this).closest('tr').click(function() { $(this).find('a[title="View Report"]').click(); }); 
}); 

但是当我点击该行我只是让所有在#list表的链接,打开窗户。我试过了一堆不同类型的jQuery调用,他们都做同样的事情。

回答

2
$('#list').on('click', 'tr', function(e) { 

    if (e.target.tagName.toLowerCase() !== 'a') { 

     $('a[title="View Report"]', this).click(); 
    } 
});​ 
+0

这似乎没有工作。 Internet Explorer一直试图打开相同的onclick链接,直到我杀死了父页面。 – Matthew 2012-07-30 19:53:30

+0

我得到SCRIPT438:对象不支持属性或方法'on' – Matthew 2012-07-30 19:56:37

+0

@matthew然后你没有使用jQuery 1.7库。 – Ohgodwhy 2012-07-30 19:57:23