mui 循环拼接追加元素方法

function getCommElement(item){
var commHtml='';
// console.log(item);
for(var i=0;i<item.length;i++){
commHtml += '<div class="borderdotted  conmm-item clearFix">'+
'<div class="imgbox mui-media-object mui-pull-left">'+
'<img class=" picmiddle" src="{customericon}">'+
'</div>'+
'<div class="commbox mui-pull-left ">'+
'<a class="username mui-pull-left">{customername}</a> '+
'<span class="mui-pull-right timecolor timerightm">{commtime}</span>'+
'<div class="clear"></div>'+
'<p class="comment-color mui-pull-left">{content}</p> '+
'</div>'+
'</div>';
commHtml = commHtml.replace(/{customericon}/,item[i].customer.face)
.replace(/{customername}/,item[i].customer.name)
.replace(/{content}/,item[i].content)
   .replace(/{commtime}/,date('Y-m-d H:i:s',item[i].uptime));
}
commHtml = [commHtml].join('');
return commHtml;

}





var table = document.body.querySelector(".commviewbox");

for(var i = 0; i < arr; i++) {
var item = data[i];
table.appendChild(getCommElement(item));
}









猜你喜欢

转载自blog.csdn.net/csdnwr/article/details/80825037
MUI