jQuery ajax拼接table

$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url:"wordMean",
data:{'article':strContent,'type':'ppl'},
type:'post',
success:function(data){
var str = "<table class='table table-bordered'>";
//根据返回的去重后的数组,拼接table,每5个一行
$.each(data,function (i,v) {
console.log(i);
if ( (i)%5 == 0 && !(i%2 == 0)){
str += "<tr>";
str += "<td>"+"<input type='checkbox' name="+v+" value="+v+">"+v+"<br>"+"</td>";
}else if ( (i+1)%5 == 0 && ((i+1)%2 == 0)){
str += "<td>"+"<input type='checkbox' name="+v+" value="+v+">"+v+"<br>"+"</td>";
str += "</tr>";
}else {
str += "<td>"+"<input type='checkbox' name="+v+" value="+v+">"+v+"<br>"+"</td>";
}
});
str += "</table>";
$('#show').html(str); //将选择的CheckBox放进show
}
},JSON);
最后修改:2019-06-20 23:11:02
0