从列表插入到数组中 [英] Insert from list into array
本文介绍了从列表插入到数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何返回当前排行榜上的一系列名称。
I wanted to know how I can return an array of names currently on the leaderboard.
这是我的代码:
function top10(maximumResults) {
//store the leaderboard elements
//check if leaderboard is less than 10
//loop through leaderboard
//return
var output2 = document.getElementById("top10").getElementsByTagName("li");
var output = "";
for(var i = 0; i < output2.length; i++) {
if(maximumResults.length < 10) {
output[i] += output2[i].id;
}
}
return output;
}
<div id=leaderboard class=panel>
<h1>Leaderboard</h1>
<ol id=top10>
<li>test</li>
<li>aaadad</li>
<li>dfghfdh</li>
<li>dfghdfhg</li>
<li>dfghfdh</li>
</ol>
</div>
推荐答案
这可以很容易地做出反应,但在这种情况下,你只需要一些jquery!:
This could be done with react very easy, but in this case all you need is some jquery!:
var array = [1, 2, 4, 5, ,6 ,7 ,8] /// here you can update with own elements
$(document).ready(function() {
for (var i = 0; i < array.length; i++) {
$("ol").append("<li>" + array[i] + "</li>")
}
})
此处演示: http://jsfiddle.net/n5phf/405/
这篇关于从列表插入到数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文