这里我通过为表数据提供动态数据来创建表行。但我没有通过他们的身份获取数据
if(xmlhttp.status == 200)
{
var adminList = xmlhttp.responseJSON;
var outputStr = '';
for(var i = 0; i < adminList.length; i++)
{
outputStr += '<tr><td id="tdusername">' + adminList[i].username + '</td><td id="tdfullname">' + adminList[i].fullName + '</td><td id="tdemail">'+ adminList[i].email+'</td><td id="tdedit">'+adminList[i].id+'</td></tr>';
}
$('#admin_list tbody').html(outputStr);
else
{
$('#msg').html(xmlhttp.status + ": " + xmlhttp.statusText);
}
&#13;
答案 0 :(得分:0)
如您所说,您点击数据以获取特定的行数据,然后我建议您将{id}添加到<tr>
var outputStr ='<table>';
for(var i = 0; i < adminList.length; i++)
{
outputStr += '<tr id="tdedit'+adminList[i].id+'" onclick="showdata('+adminList[i].id+')"><td id="tdusername">' + adminList[i].username + '</td><td id="tdfullname">' + adminList[i].fullName + '</td><td id="tdemail">'+ adminList[i].email+'</td><td id="tdedit">'+adminList[i].id+'</td></tr>';
}
outputStr +='</table>';
function showdata(id){
var row = document.getElementById('tdedit'+id);
//now you can access all column by their index
var username=row.cells[0].innerHTML;
var fullname=row.cells[1].innerHTML;
var email=row.cells[2].innerHTML;
}