这是 json 数据
[
{
"content":"ffffffff ",
"doctorAddress":"img/1.png",
"doctorId":1,
"doctorName":"杨小松",
"img":[
{
"headId":1,
"imgAddress":"img/1.jpg",
"imgAddressId":1
},
{
"headId":1,
"imgAddress":"img/2.jpg",
"imgAddressId":2
}
],
},
{
"content":"ffffffff",
"doctorAddress":"img/1.png",
"doctorId":1,
"doctorName":"杨小松",
"img":[
{
"headId":7,
"imgAddress":"img/2.jpg",
"imgAddressId":4
}
],
}
]
ajax后 用for循环拼接
var MainCortent='';
var MainCortentImg='';
for (var i=0;i' +
''+data[i].content+'
' +
''+data[i].content+'
'++'' +
'';
for(var j=0;j< data[i].img.length;j++){
MainCortentImg+=''+ data[i].img[j].imgAddress+'
'
}
}
$(".main").html(MainCortent);
$(".img")html(MainCortentImg);
大概的dom结构是:
效果本来是第一个section里面的img里面放两张图片,第二发一张。
可是运行发现每个盒子里面都是三张。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
不晓得是不是这样的效果。