2016-02-25 2 views
-1

Мой код первого элемента, мне нужен второй и третий элемент, как я могу это сделать?Получение значения от td

$(".button").click(function(){  
    var value=$(this).closest('tr').children('td:first').text(); 
    console.log(value); 
}); 
+1

Пожалуйста, прочтите [как спросить] (http://stackoverflow.com/help/how-to-ask). – micstr

ответ

1

Использование eq() способ, как нижеследующий.

$(".button").click(function() { 
    var tds = $(this).closest('tr').find('td'); 

    var first = tds.eq(0).text(); 
    var second = tds.eq(1).text(); 
    var third = tds.eq(2).text(); 
}); 
0

Вы можете дать как этот

$(".button").click(function(){  
     var second=$(this).closest('tr').children('td:nth-child(2)').text(); 
     var third=$(this).closest('tr').children('td:nth-child(3)').text(); 
     console.log(seond + " "+third); 
}); 
Смежные вопросы