Getting td by index with jQuery

后端 未结 3 1073
感动是毒
感动是毒 2020-12-13 09:00

I know how to get a cell\'s row and column index with jQuery, but I can\'t figure out the reverse. Given a row and column index, how would I access the td at this location?<

3条回答
  •  时光取名叫无心
    2020-12-13 09:58

    How about using the nth-child selector?

    http://api.jquery.com/nth-child-selector/

    var row = 4;
    var col = 2
    
    var cell = $('table#tableId tr:nth-child(' + row + ') td:nth-child(' + col + ')');
    

    Note that the child index is 1-based, rather than the more usual 0-based.

提交回复
热议问题