簡體   English   中英

如何使用Row索引和td索引在td中獲取元素

[英]How to get element inside a td using Row index and td index

我在表中有一個Row IndexTD index ,我想在[Row Index,TD Index]選擇單元格內的input元素。 我怎么能這樣做?

表具有用於直接訪問單個單元的訪問器屬性,即:

table.rows[rowIndex].cells[colIndex]

因此:

table.rows[rowIndex].cells[colIndex].getElementsByTagName('input')[0];

要么:

$('input', table.rows[rowIndex].cells[colIndex])

這應該工作:

$('tr:eq(rowIndex) td:eq(tdIndex) input')

:eq選擇器以獲取更多信息。

var rowIndex = X;
var cellIndex = Y;
$('#my-table tbody')
    .children(':nth-child('+(rowIndex+1)+')')
      .children(':nth-child('+(cellIndex+1)+')')
        .find('input').val('Hello');

當然你可以將em放在一個選擇器上

$('#my-table tbody tr:nth-child('+(rowIndex+1)+') td:nth-child('+(cellIndex+1)+')')
        .find('input').val('Hello');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM