2 回答
TA贡献1828条经验 获得超3个赞
ES6版本
const getRandomInt = ((min, max) => Math.floor(Math.random() * (max - min + 1)) + min);
const list = document.querySelectorAll('#my_list li');
[...Array(list.length - 1)
.fill()
.map(() => getRandomInt(30, 99)),
100]
.sort((a, b) => b - a)
.forEach((item, i) => {
list[i].appendChild(document.createTextNode(item + '%'));
})
<ol class="row top20" id="my_list">
<li class="list_item">
<div class="showcase col-sm-6 col-md-4">
<a href="#">
<h3>Title 1</h3>
<h5>Destination 1</h5>
<img src="..." class="img-responsive">
</a>
</div>
</li>
<li class="list_item">
<div class="showcase col-sm-6 col-md-4">
<a href="#">
<h3>Title 2</h3>
<h5>Destination 2</h5>
<img src="..." class="img-responsive">
</a>
</div>
</li>
<li class="list_item">
<div class="showcase col-sm-6 col-md-4">
<a href="#">
<h3>Title 3</h3>
<h5>Destination 3</h5>
<img src="..." class="img-responsive">
</a>
</div>
</li>
</ol>
添加回答
举报