0
我想讀這個網站名單:使用Javascript - 在閱讀HTML列表
<div id="leaderboard" class="panel">
<h1>Leaderboard</h1>
<ol id=top10>
<li>yeah</li>
<li>grgsdg</li>
<li>dfhdfhdfh</li>
<li>Ttest</li>
</ol>
</div>
<script>
console.log(leaders());
function leaders() {
//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 = 1; i < output2.length; i++) {
//if(maximumResults.length < 10) {
//output2[i] = output[i];
output.push(output2[i].textContent);
//}
}
return output;
}
</script>
這是我到目前爲止有:
但是,它只輸出元素索引( 0,1,2,3)等等。而不是列表中的實際字符串
集我爲0變種I = 0後,檢查控制檯; –
當你將JS分成不同的片段和它需要工作的HTML(以及當你沒有提供調用JS函數的方法)時,你使用實時片段毫無意義。 – Quentin
這個問題與[你的最後](http://stackoverflow.com/questions/40390298/insert-from-list-into-array)有什麼不同? – j08691