单击位于的链接

时间:2013-11-11 20:14:05

标签: jquery html

我有一张简单的表格:

 <tr>
   <td>
    <a href="/patients/5"> … </a>
   </td>
   ....

我试图在用户点击tr时触发链接: 所以我写了这段代码:

<script>
 $("tr").click(function(){
  this.next("a").click();
 })
</script>

首先我得到了这个错误:

Object #<HTMLTableRowElement> has no method 'next' 

接下来我试过了:

<script>
 $("tr").click(function(){
  this.siblings().click();
 })
</script>

但后来我收到了这个错误:

 Object #<HTMLTableRowElement> has no method 'siblings' 

我错了什么?

1 个答案:

答案 0 :(得分:2)

$(this).find("a")[0].click()这会触发它。

下面会触发此链接的点击处理程序。

$("tr").click(function(){
  $(this).find("a").first().trigger('click');
})

<强> jsFIddle DEMO