如何从jQuery中的同一行中选择不同的单元格?

gsk*_*ema 2 jquery html-table jquery-selectors

我有这个jQuery选择器:

'table tbody tr td:first-of-type'
Run Code Online (Sandbox Code Playgroud)

如何从$(this)构造同一行的单元格选择器?我需要检查一下

 $(document).on('click','table tbody tr td:first-of-type',function()
 {
   if ( $('table tbody tr td:nth-child(2)').text() != "" ) // for the same row !!
   //do something
   else
   //do something else
 }
Run Code Online (Sandbox Code Playgroud)

额外的问题:我应该避免使用像nth-child()这样的CSS3选择器并使用像eq()这样的jquery选择器吗?

tym*_*eJV 5

找到最近的 tr

$(this).closest("tr")
Run Code Online (Sandbox Code Playgroud)

并选择a td,使用.find()链接到:

$(this).closest("tr").find("td") //and whatever criteria you need
Run Code Online (Sandbox Code Playgroud)