x
1
<p>点击按钮列出数组的每个元素。</p>
2
<button onclick="numbers.forEach(myFunction)">点我</button>
3
<p id="demo"></p>
4
5
<script>
6
demoP = document.getElementById("demo");
7
var numbers = [4, 9, 16, 25];
8
9
function myFunction(item, index) {
10
demoP.innerHTML = demoP.innerHTML + "index[" + index + "]: " + item + "<br>";
11
}
12
</script>