大概是这样
序号 | 数值 | 序号 | 数值 |
---|---|---|---|
1 | 张珊 | 2 | 张三 |
3 | 张珊 | 4 | 张三 |
5 | 张珊 | 6 | 张三 |
//查询数据
function selectNewData(){
$.ajax({
type: "POST",//方法类型
dataType: "json",//预期服务器返回的数据类型
url: "form/selectNewData.action" ,//url
async: false,
success: function (data) {
var str="";
for (var i = 0; i <data.length; i++) {
if(i%2==1){
var createTr= $(str+'<td style="color: #7992a8;font-size: 13px;">' + (i+1) + '</td>' +
'<td style="color: #7992a8;font-size: 13px;">' + data[i].deviceName + '</td>' +
'<td style="color: #7992a8;font-size: 13px;">' + data[i].color + '</td></tr>');
$('#body').append(createTr);
str="";
}else if(i%2!=1){
str = '<tr style="color: #7992a8;text-align: center;font-size: 13px;"><td style="color: #7992a8">' + (i+1) + '</td>' +
'<td style="color: #7992a8;font-size: 13px;">' + data[i].deviceName + '</td>' +
'<td style="color: #7992a8;font-size: 13px;">' + data[i].color + '</td>' ;
} else if(data.length%2!=1&&i!=data.length){
//如果数据的长度是奇数 最后一个直接插入
createTr = $('<tr style="color: #7992a8;text-align: center;font-size: 13px;"><td style="color: #7992a8">' + (i+1) + '</td>' +
'<td style="color: #7992a8;font-size: 13px;">' + data[i].deviceName + '</td>' +
'<td style="color: #7992a8;font-size: 13px;">' + data[i].color + '</td></tr>' );
}
}
},
});
}