You need to add an onClick which is different for every row, in there you pass as parameter the row index :) than you can handle it on the function.
(您需要添加每行不同的onClick,在该行中您将传递行索引()作为参数传递给函数,而不是您可以在函数上进行处理。)
var html = "<table>";
for (var i = 0; i < data.length; i++) {
html+="<tr onclick="myFunction("+i+")">";
html+="<td>"+data[i].personName+"</td>";
html+="<td>"+data[i].fatherName+"</td>";
html+="<td>"+data[i].personPhone+"</td>";
html+="<td>"+data[i].personCnic+"</td>";
html+="<td>"+data[i].deliveryDate+"</td>";
html+="<td>"+data[i].submissionDate+"</td>";
html+="<td>"+data[i].year+"</td>";
html+="<td>"+data[i].session+"</td>";
html+="<td>"+data[i].board+"</td>";
html+="<td>"+data[i].amount+"</td>";
html+="</tr>";
}
html+="</table>";
function myFunction(x) {
console.log('index' + x + 'was clicked')
// do the handling here
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…