非jQuery解决方案
var span = document.getElementById('part1');
var row = span.getElementsByTagName('table')[2].childNodes[2];
jQuery解决方案
使用:eq选择器:
var $row = $('#part1 > table:eq(2) > tr:eq(2)');
使用:nth-child选择器:
var $row = $('#part1 > table:nth-child(3) > tr:nth-child(3)');
:eq和:nth-child选择器选择所有父元素的nth-child元素.但是:eq遵循“0索引”计数,而nth-child遵循“1索引”.
请注意:eq和nth:子选择器的工作方式不同.在这种情况下,它会执行相同的操作,因为span#part1中只有表元素.
从jQuery文档:
The :nth-child(n) pseudo-class is easily confused with :eq(n), even
though the two can result in dramatically different matched elements.
With :nth-child(n), all children are counted, regardless of what they
are, and the specified element is selected only if it matches the
selector attached to the pseudo-class. With :eq(n) only the selector
attached to the pseudo-class is counted, not limited to children of
any other element, and the (n+1)th one (n is 0-based) is selected.
参考: