<div id="showtable">
</div>
function getData(){
$.ajax({
type: "get", //以POST的方式发送请求
url: "testBoot/query",
data:"", //上面拼凑的链接及参数
// contentType: "application/json",
dataType: "json",
success: function (data) {
dataa=data;
//将数据显示在页面上
var str = "";
str +="<table class=\"table table-bordered table-striped table-hover \" id='tabletest'>\n" +
" <tr>\n" +
" <th style='text-align: center;'><input type=\"checkbox\" class=\"form-check-input\" id=\"\" value=\"\" /></th>\n" +
" <th style='text-align: center;'>用户id</th>\n" +
" <th style='text-align: center;'>用户姓名</th>\n" +
" <th style='text-align: center;'>用户密码</th>\n" +
" <th style='text-align: center;'>用户名</th>\n" +
" <th style='text-align: center;' class=\"col-md-2\">操作</th>\n" +
" </tr>\n" +
"";
//遍历数据
$.each(data,function(index,element){
str +="<tr><td>"+'<input style="align: center" type="checkbox" value="" />'+"</td><td>"+element['id']+"</td><td>"+element['userName']+"</td><td>"+element['passWord']+"</td><td>"+element['realName']+"</td><td>"+'<button id="b1" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal" onclick="update(this)">修改</button>' +'<a href="#" style="margin-left: 10px" class="btn btn-danger btn-sm " onclick="delTable(\''+element['id']+'\')">删除</a>'+"</td></tr>";
})
$('#showtable').append(str);
},
});
}
function update(btn){
var idx=$(btn).parent().parent().index()
console.log(idx)
id=dataa[idx-1].id
$("#uname").val(dataa[idx-1].userName);
$("#upwd").val(dataa[idx-1].passWord);
$("#realName").val(dataa[idx-1].realName);
}