2016-02-25 88 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); 
});