js 一数组分割成若干个数组,并装换成字符串赋个li标签
Posted 11个条子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js 一数组分割成若干个数组,并装换成字符串赋个li标签相关的知识,希望对你有一定的参考价值。
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标签的主要内容,如果未能解决你的问题,请参考以下文章