var val = [ 'aa','bb','cc','|', 'dd','ee','ff','|'
];//...理想输出的数据格式为以 '|'分割为一行,向下循环<p> <span>aa</span>
<span>bb</span>
<span>cc</span></p><p>
<span>dd</span>
<span>ee</span>
<span>ff</span></p>思路乱了
1 回答
小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
var arr=['aa','bb','cc','|', 'dd','ee','ff','|'];
var html=arr.reduce(function (str, item) {
return item=='|'?str+item:str+'<span>'+item+'</span>'
},'');
html=html.split('|').map(function (item) {
return item?'<p>'+item+'</p>':'';
});
html=html.join('');
console.log(html);
添加回答
举报
0/150
提交
取消