success:function(json){标签:body,解决办法,每行,前端,list,replace,html,let,div From: https://www.cnblogs.com/elaine-a/p/17066463.html
let list=json.data;
let test='<div class="col-md-offset-1 col-md-10"></div>'
for (let i = 0; i <list.length ; i++) {
let html='<div class="col-md-3">\n' +
'<div class="goods-panel">\n' +
'<img src="..#{image}/collect.png" class="img-responsive" />\n' +
'<p>¥#{price}</p>\n' +
'<p class="text-row-3"><a href="product.html?#{pid}"><small>#{title}</small></a></p>\n' +
'<span>\n' +
'<a href="javascript:void(0)" class="btn btn-default btn-xs add-fav"><span class="fa fa-heart-o"></span>加入收藏</a>\n' +
'<a href="cart.html" class="btn btn-default btn-xs add-cart"><span class="fa fa-cart-arrow-down"></span>加入购物车</a>\n' +
'</span>\n' +
'</div>'
html=html.replace(/#{image}/g,list[i].image);
html=html.replace(/#{price}/g,list[i].price);
html=html.replace(/#{title}/g,list[i].title);
if(i%4==0){
$("body > div.container").append(test);
j++;}
console.log(j);
console.log(`body > div.container > div:nth-child(${j})`);
$(`body > div.container > div:nth-child(${j})`).append(html);
}
},
error:function (xhr){
alert("产生未知错误!"+xhr.status)
}