我有这个jQuery选择器:
'table tbody tr td:first-of-type'
如何从$(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
}
额外的问题:我应该避免使用像nth-child()这样的CSS3选择器,而应该像eq()这样使用jquery选择器吗?
只要找到最近的 tr
$(this).closest("tr")
并选择td
,使用.find()
链接到该链接:
$(this).closest("tr").find("td") //and whatever criteria you need
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句