实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>手册网教程(shouce.ren)</title>
6
</head>
7
<body>
8
9
<p>点击按钮列出数组的每个元素。</p>
10
<button onclick="numbers.forEach(myFunction)">点我</button>
11
<p id="demo"></p>
12
13
<script>
14
demoP = document.getElementById("demo");
15
var numbers = [4, 9, 16, 25];
16
17
function myFunction(item, index) {
18
    demoP.innerHTML = demoP.innerHTML + "index[" + index + "]: " + item + "<br>"; 
19
}
20
</script>
21
22
</body>
23
</html>