码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-07-23 16:06:29      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:++   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(‘<div class="col-md-3 col-sm-6 col-xs-6">‘
                            + ‘<img src="‘ + data[i].img + ‘" width="240" height="180"/>‘
                            + ‘</div>‘)

                    }
                   
                    var len = ihtml.length/4;
                    len = parseInt(ihtml.length%4!=0?len+1:len);
                    console.log(len);
                    for(var i=0;i<len;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 += ‘<li>‘ +
                            ‘‘ + (ihtml.slice(start,end)).join("") + ‘‘ +
                            ‘</li>‘
                            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">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/01.png" width="190">
                            <!-- </a> -->
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/02.png" width="190">
                            <!-- </a> -->
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/03.png" width="190">
                            <!-- </a> -->
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/04.png" width="190">
                            <!-- </a> -->
                        </div>
                    </li>
                    <li class="li2">
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/05.png" width="190">
                            <!-- </a> -->
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/06.png" width="190">
                            <!-- </a> -->
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/07.png" width="190">
                            <!-- </a> -->
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/08.png" width="190">
                            <!-- </a> -->
                        </div>
                    </li>
                    <li class="li3">
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/09.jpg" width="190">
                            <!-- </a> -->
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/10.jpg" width="190" height="120">
                            <!-- </a> -->
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/07.png" width="190">
                            <!-- </a> -->
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-6">
                            <!-- <a href="javascript:return false;" target="_blank"> -->
                            <img src="img/08.png" width="190">
                            <!-- </a> -->
                        </div>
                    </li>
                </ul>

 

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!