js 一数组分割成若干个数组,并装换成字符串赋个li标签

2021-04-10 20:28

阅读:671

标签:++   res   lan   html   success   处理   n+1   OLE   java   

success: function (datas) { //请求成功后处理函数。
                    var htmltext = ‘‘;
                    var data = datas.result;
                    console.log(data)
                    var ihtml = [];
                    for (var i in data) {
                        ihtml.push(
‘ + ‘‘ + ‘
) } var len = ihtml.length/4; len = parseInt(ihtml.length%4!=0?len+1:len); console.log(len); for(var i=0;i){ var start = i*4; var end = start+4; end = end>ihtml.length?ihtml.length:end; ihtml.slice(start,end); console.log(ihtml.slice(start,end)) htmltext += ‘
  • ‘ + ‘‘ + (ihtml.slice(start,end)).join("") + ‘‘ + ‘
  • console.log(1) } console.log(ihtml) console.log(htmltext); $(".coop-ul").html(htmltext); },
    ul class="coop-ul">
                        li>
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/01.png" width="190">
                                
                            div>
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/02.png" width="190">
                                
                            div>
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/03.png" width="190">
                                
                            div>
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/04.png" width="190">
                                
                            div>
                        li>
                        li class="li2">
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/05.png" width="190">
                                
                            div>
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/06.png" width="190">
                                
                            div>
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/07.png" width="190">
                                
                            div>
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/08.png" width="190">
                                
                            div>
                        li>
                        li class="li3">
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/09.jpg" width="190">
                                
                            div>
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/10.jpg" width="190" height="120">
                                
                            div>
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/07.png" width="190">
                                
                            div>
                            div class="col-md-3 col-sm-6 col-xs-6">
                                
                                img src="img/08.png" width="190">
                                
                            div>
                        li>
                    ul>

     

    js 一数组分割成若干个数组,并装换成字符串赋个li标签

    标签:++   res   lan   html   success   处理   n+1   OLE   java   

    原文地址:https://www.cnblogs.com/opcec/p/13365658.html


    评论


    亲,登录后才可以留言!