[英]How to get element inside a td using Row index and td index
我在表中有一個Row Index
和TD 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])
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.