我有三组数组,我从循环和排序json数据得到。比方说, arr1 , arr2 , arr3 。我想输出那些与HTML代码组合五次的数组。到目前为止,我有这段代码:
var max=5;
for (var b = 0;b < max;b++) {
var conEl = $('#container');
var newConEl = conEl.html();
newConEl = '<ul>';
var newProp = '<li><span><a href="'+arr1[b]+'">'+arr2[b]+'</a><span>'+arr3[b]+'</span></span></li>';
newConEl += newProp + '</ul>';
return conEl.html(newConEl);
}
但是,这只输出一个结果。这是结果:
<div>
<span>
<a href="#link-to-result-1">result-1-title</a>
<span>view-count-1</span>
</span>
</div>
虽然,我希望有五个输出。我想要的结果是:
<div>
<span>
<a href="#link-to-result-1">result-1-title</a>
<span>view-count-1</span>
</span>
<span>
<a href="#link-to-result-2">result-2-title</a>
<span>view-count-2</span>
</span>
<span>
<a href="#link-to-result-3">result-3-title</a>
<span>view-count-3</span>
</span>
<span>...</span>
</div>
使用 document.write(newProp); 时,我得到了所需的输出(五个输出)。但是,我不想使用document.write方法。