jQuery:在行的onclick函数中指定子<td>的索引

mat*_*att 2 jquery jquery-selectors

我有一个表行的click函数,需要传递行中前两个tds的内容.

// Assign a click handler to the rows
$('#supportTables1 tr').click(function ()
{
    var firstTd = $(this).find('td').html();
    //need to get the next td.  below line doesn't work.
    var secondTd = $(this).find('td')[1].html();
    window.open('snglContactList.php'+'?search_word='+firstTD+'?list_name=secondTd);
});
Run Code Online (Sandbox Code Playgroud)

我可以得到第一个td就好了,但是我很难理解我确定访问第二个td非常简单的问题(我尝试过设置它的索引的不同方法).

lon*_*day 5

数组表示法[1]返回一个DOM元素,而不是一个jQuery对象,所以你不能使用它.html()(一个jQuery方法).使用jQuery函数.eq()来获取元素:

  // Assign a click handler to the rows
  $('#supportTables1 tr').click(function ()
  {
        var firstTd = $(this).find('td').eq(0).html();
        var secondTd = $(this).find('td').eq(1).html();
        window.open('snglContactList.php'+'?search_word='+firstTD+'?list_name='+secondTd);
  });
Run Code Online (Sandbox Code Playgroud)