ユーザーが行ったチェック ボックスの選択に基づいて、テーブル内の特定の行からデータを取得しようとしています。
このために、私は と の 2 つの方法を見つけましeq(rowIndex)
たnth-child(rowIndex)
。ただし、動的な場合ではなく、絶対値が指定された場合にのみ機能します。
次のことを試しましたが、これについては運がありません:
function getData()
{
var chkArr = document.getElementsByName('checkbox');
var checkedRecord = 0;
for(var i=0; i<chkArr.length; i++)
{
if(chkArr[i].checked)
{
checkedRecord = i;
$('#summaryTable > tbody > tr').eq('#checkedRecord').children('td').each(function(j)
//checkedRecord is the row index here
{
//fetch values from td
});
}
}
}
これが私のhtmlの外観です
<table>
<tr>
<td><input type="text" id="text1"></td>
<td>
<select>
<option value="opt1">Orange</option>
<option value="opt2">Green</option>
</select>
</td>
</tr>
<tr>..</tr>
これに関する提案はありますか?