留言板数据循环显示

<!DOCTYPE html>
<html>


<head>
<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
<style>


#div1{
width:350px;
height:70px;
padding:10px;
border:1px solid #aaaaaa;
}
</style>
<script src="js/jquery.min.js"></script>
<script>



var data=
[
{"id":25,"name":"joy211","picture":"http:\/\/image.tianjimedia.com\/uploadImages\/2015\/083\/30\/VVJ04M7P71W2.jpg","sex":"\u5973","fid":"24","content":"\u53ea\u662f\u7f51\u7edc\u90e8\u3002","created_at":"2016-09-02 05:50:02"},{"id":24,"name":"ap2016","picture":"http:\/\/img1.imgtn.bdimg.com\/it\/u=289544345,272172998&fm=21&gp=0.jpg","sex":"\u5973","fid":"15","content":"\u6240\u6709\u90e8\u95e8\u5417(\u2299o\u2299)\u2026","created_at":"2016-09-02 05:50:02"},{"id":23,"name":"djy2016","picture":"http:\/\/img1.imgtn.bdimg.com\/it\/u=289544345,272172998&fm=21&gp=0.jpg","sex":"\u5973","fid":"15","content":"\u52a0\u73ed\uff0c\u597d\u554a(\u2299o\u2299)\u2026","created_at":"2016-09-02 05:50:02"},{"id":22,"name":"Ljn2016","picture":"http:\/\/img1.imgtn.bdimg.com\/it\/u=289544345,272172998&fm=21&gp=0.jpg","sex":"\u5973","fid":"21","content":"\u4e0b\u5468\u8ddf\u4eba\u7ea6\u4e86\u53bb\u722c\u5c71\uff0c\u4f60\u53bb\u5417\uff1f\u4ecb\u7ecd\u59b9\u7eb8\u7ed9\u4f60\u8ba4\u8bc6\u554a\u54c8\u54c8\u54c8\u54c8O(\u2229_\u2229)O~","created_at":"2016-09-02 05:50:02"},{"id":21,"name":"tzz111","picture":"http:\/\/img1.imgtn.bdimg.com\/it\/u=289544345,272172998&fm=21&gp=0.jpg","sex":"\u5973","fid":"20","content":"\u4e0b\u5468\u53bb\u5457\uff0c\u7ea6\u4e48\uff0cO(\u2229_\u2229)O~","created_at":"2016-09-02 05:50:02"},{"id":20,"name":"Ljn2016","picture":"http:\/\/img1.imgtn.bdimg.com\/it\/u=289544345,272172998&fm=21&gp=0.jpg","sex":"\u5973","fid":"17","content":"\u660e\u5929\u60f3\u53bb\u70e7\u70e4\uff0c\u770b\u6765\u53c8\u53bb\u4e0d\u4e86\u4e86O(\u2229_\u2229)O~","created_at":"2016-09-02 05:50:02"},{"id":19,"name":"tzz111","picture":"http:\/\/img1.imgtn.bdimg.com\/it\/u=289544345,272172998&fm=21&gp=0.jpg","sex":"\u5973","fid":"17","content":"\u52b3\u9038\u7ed3\u5408\u54c8\uff0cO(\u2229_\u2229)O~","created_at":"2016-09-02 05:50:02"},{"id":18,"name":"GaoChunRong","picture":"http:\/\/life.ce.cn \/gd\/201607\/27\/W020160727566742692591.jpg","sex":"\u7537","fid":"17","content":"\u5de5\u4f5c\u6ca1\u5b8c\u6210\uff0c\u8fd8\u662f\u52a0\u73ed\u5427\uff0cO(\u2229_\u2229)O~","created_at":"2016-09-02 05:50:02"},{"id":17,"name":"LiPen111","picture":"http:\/\/cdn.duitang.com\/uploads\/item\/201408\/30\/20140830125856_kaNPk.jpeg","sex":"\u5973","fid":"15","content":"\u4e0d\u8981\uff0c\u4e0d\u8981^\\\/^","created_at":"2016-09-02 05:50:02"},{"id":15,"name":"joy211","picture":"http:\/\/image.tianjimedia.com\/uploadImages\/2015\/083\/30\/VVJ04M7P71W2.jpg","sex":"\u5973","fid":null,"content":"\u660e\u5929\u8981\u52a0\u73ed!","created_at":"2016-09-02 05:50:02"},{"id":16,"name":"joy211","picture":"http:\/\/image.tianjimedia.com\/uploadImages\/2015\/083\/30\/VVJ04M7P71W2.jpg","sex":"\u5973","fid":null,"content":"\u4e2d\u79cb\u8282\u53bb\u54ea\u513f\u6d6a\u554a\uff1f","created_at":"2016-09-02 05:51:38"},{"id":26,"name":"ap2016","picture":"http:\/\/img1.imgtn.bdimg.com\/it\/u=289544345,272172998&fm=21&gp=0.jpg","sex":"\u5973","fid":"25","content":"\u597d\u8bf6\uff0c\u660e\u5929\u53ef\u4ee5\u8ddf\u670b\u53cb\u51fa\u53bb\u6d6a\u4e86O(\u2229_\u2229)O","created_at":"2016-09-02 05:50:02"},{"id":27,"name":"LiPen111","picture":"http:\/\/cdn.duitang.com\/uploads\/item\/201408\/30\/20140830125856_kaNPk.jpeg","sex":"\u5973","fid":"16","content":"\u8fd8\u6ca1\u60f3\u597d\u5462\uff0c\u4f60\u8981\u7ea6\u6211\u4e48O(\u2229_\u2229)O","created_at":"2016-09-02 05:50:02"},{"id":28,"name":"GaoChunRong","picture":"http:\/\/life.ce.cn \/gd\/201607\/27\/W020160727566742692591.jpg","sex":"\u7537","fid":"27","content":"\u6211\u7ea6\u4f60\u597d\u4e48O(\u2229_\u2229)O","created_at":"2016-09-02 05:50:02"},{"id":29,"name":"LiPen111","picture":"http:\/\/cdn.duitang.com\/uploads\/item\/201408\/30\/20140830125856_kaNPk.jpeg","sex":"\u5973","fid":"28","content":"\u4e0d\u7ea6\uff0c\u6211\u4eec\u4e0d\u7ea6O(\u2229_\u2229)O","created_at":"2016-09-02 05:50:02"},{"id":30,"name":"tzz111","picture":"http:\/\/img1.imgtn.bdimg.com\/it\/u=289544345,272172998&fm=21&gp=0.jpg","sex":"\u5973","fid":"16","content":"\u53a6\u95e8\uff0c\u9f13\u6d6a\u5c7f\u8d70\u8d77O(\u2229_\u2229)O","created_at":"2016-09-02 05:50:02"}
];


</script>
</head>
<body>
<div id="box"></div>







<script>
//console.log(data.length);
function fc(farr,carr){
//console.log(farr);
//console.log(carr);
for(var n=0;n<farr.length;n++){//输出话题与留言
for(var m=0;m<carr.length;m++){
if(farr[n].id==carr[m].fid){
console.log($("."+farr[n].id).attr('class'));
if($("."+farr[n].id).length==0){
$("#box").append("<div class="+farr[n].id+">"+farr[n].name+":"+farr[n].content+"</div><div class="+carr[m].id+">"+carr[m].name+"回复"+farr[n].name+":"+carr[m].content+"</div>" );
//console.log(farr[n].id+"1"+carr[m].id);
}else if($("."+farr[n].id).length>=1){
//console.log(farr[n].id+"2"+carr[m].id);
$("."+farr[n].id).append("<div class="+carr[m].id+">"+carr[m].name+"回复"+farr[n].name+":"+carr[m].content+"</div>" );
}
//$("#box").append("<div class="+farr[n].id+">"+farr[n].name+":"+farr[n].content+"</div><div class="+carr[m].id+">"+carr[m].name+":"+carr[m].content+"</div>" );


}
}


}
//console.log(farr);
//console.log(carr);
var fcarr = [];
for(var i=0;i<farr.length;i++){//重组数组数据
//console.log(farr[i]);
for(var j=0;j<carr.length;j++){
if(farr[i].id==carr[j].fid){
//console.log(carr[j]);
fcarr.push(carr[j]);
}
}
}


if(fcarr.length>0){//话题数 的数量  
fc(fcarr,carr)
}

}


function arr(data){
var farr = [];//主数组,用于循环第一条话题
var carr = [];// 副数组,用于循环留言
for(var i=0;i<data.length;i++){
//console.log(data[i]);
if(data[i].fid==null){
//console.log(data[i]);
farr.push(data[i]);
}else {
carr.push(data[i]);
}
}
//console.log(farr+"----|----"+carr);
fc(farr,carr);
}


arr(data);//编写需要循环的数组数据
</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值